 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marco Ponti Guest
|
Posted: Thu Apr 22, 2004 3:07 pm Post subject: TImage resize and canvas |
|
|
Hi all,
I'm drawing on the canvas of a TImage, changing the color of some of the
pixels. The TImage is on a panel that can be resized by the user at runtime.
In response to a change in the panel's size i resize accordingly the TImage,
and i expect the picture to do the same, but the size of the picture doesn't
change (while the size of the TImage is actually changed).
I've tried using the Stretch property of TImage but without results, maybe
because i'm using the canvas directly?
Is there a way to stretch the content of the canvas?
Thanks,
Marco
|
|
| Back to top |
|
 |
Joseph F. Muscarella Guest
|
Posted: Thu Apr 22, 2004 4:47 pm Post subject: Re: TImage resize and canvas |
|
|
| Quote: | I'm drawing on the canvas of a TImage, changing the color of some of the
pixels. The TImage is on a panel that can be resized by the user at
runtime.
In response to a change in the panel's size i resize accordingly the
TImage,
and i expect the picture to do the same, but the size of the picture
doesn't
change (while the size of the TImage is actually changed).
I've tried using the Stretch property of TImage but without results, maybe
because i'm using the canvas directly?
Is there a way to stretch the content of the canvas?
|
Don't draw directly on the TImage. Instead, use a memory bitmap for
drawing. When your drawing is finished, give the bitmap to the image.
std::auto_ptr<Graphics::TBitmap> temp_bitmap(new Graphics::TBitmap);
temp_bitmap->Width = Panel->Width;
temp_bitmap->Height = Panel->Height;
do the drawing...
Image->Width = temp_bitmap->Width;
Image->Height = temp_bitmap->Height;
Image->Picture->Graphic = temp_bitmap.get();
You must replace the Picture->Graphic for the displayed image to really
change size.
I hope this helps.
Joe
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Thu Apr 22, 2004 6:52 pm Post subject: Re: TImage resize and canvas |
|
|
"Marco Ponti" <marco.ponti (AT) nospam (DOT) nimaxit.com> wrote:
| Quote: | [...] I've tried using the Stretch property of TImage but
without results,
|
Setting the Stretched property to true will cause the image to
be sized poportionally when it's drawn. IOW, if:
Image1->Height = 100;
Image1->Width = 100;
Image1->Stretched = true;
Image1->Picture->Width = 200;
Image1->Picture->Height = 200;
when the image is painted, it will be 'stretched' (shrunk in
this case) when it's drawn. Set Stretched to false and all you
will see is the first 100 pixels of the first 100 rows.
| Quote: | maybe because i'm using the canvas directly?
|
That's the only way to do what you want.
| Quote: | Is there a way to stretch the content of the canvas?
|
How are you actually drawing the image onto the canvas? You should be using StretchDraw:
Image1->Stretched = true;
TRect R = Rect( 0, 0, pCanvas->Width - 1, pCanvas->Height - 1 );
pCanvas->StretchDraw( R, Image1->Picture->Bitmap );
~ JD
|
|
| Back to top |
|
 |
Marco Ponti Guest
|
Posted: Fri Apr 23, 2004 6:32 am Post subject: Re: TImage resize and canvas |
|
|
"JD" <nospam (AT) nospam (DOT) com> ha scritto nel messaggio
news:40881483$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
How are you actually drawing the image onto the canvas? You should be
using StretchDraw:
|
The image i need to draw is encoded in a binary file and i change the color
of some of the pixel in the canvas using
theImage->Canvas->Pixels[X][Y] = clBlue
|
|
| Back to top |
|
 |
Marco Ponti Guest
|
Posted: Fri Apr 23, 2004 7:58 am Post subject: Re: TImage resize and canvas |
|
|
"Joseph F. Muscarella" <joe (AT) infosight-DISCARDMUNG- (DOT) com> ha scritto nel
messaggio news:4087f708$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Don't draw directly on the TImage. Instead, use a memory bitmap for
drawing. When your drawing is finished, give the bitmap to the image.
|
Thanks, that worked great !
Marco
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Apr 23, 2004 8:21 am Post subject: Re: TImage resize and canvas |
|
|
"Marco Ponti" <marco.ponti (AT) nospam (DOT) nimaxit.com> wrote:
| Quote: | How are you actually drawing the image onto the canvas? You
should be using StretchDraw:
The image i need to draw is encoded in a binary file and i
change the color of some of the pixel in the canvas using
theImage->Canvas->Pixels[X][Y] = clBlue
|
I wasn't asking how you change the pixels in the bitmap but
rather how you are drawing it on the screen. Did you try the
code that I posted?
~ JD
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|