 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vladimir Stefanovic Guest
|
Posted: Sun Jan 25, 2004 5:01 pm Post subject: Some questions about TImage... |
|
|
Hello,
I have some misunderstanding about TImage. Suppose I
have two TImage objects: SrcImage and DstImage.
I can load some image into SrcImage...
SrcImage->Picture->LoadFromFile()
....if the file type is supported:
* JPEG Image File (*.jpg, *.jpeg),
* Bitmaps (*.bmp),
* Icons (*.ico),
* Metafiles (*.wmf) and
* Enhanced Metafiles (*.emf).
.... after loading sometimes I have a need to Assign()
SrcImage to some other image (DstImage) object.
Here is my first question. Should I always use:
SrcImage->Picture->Assign( DstImage->Picture );
or, depending of a file type (*.bmp, ...)
SrcImage->Picture->Bitmap->Assign( DstImage->Picture->Bitmap );
Sometimes I grab image from screen:
HDC dc = GetDC( hSomeWindow );
Graphics::TCanvas *ScreenCanvas = new Graphics::TCanvas;
ScreenCanvas->Handle = dc;
TRect MRectangle = ScreenCanvas->ClipRect;
MRectangle.Top = 0;
MRectangle.Left = 0;
MRectangle.Right = MRectangle.Right - MRectangle.Left;
MRectangle.Bottom = MRectangle.Bottom - MRectangle.Top;
SrcImage->Picture->Bitmap->Width = MRectangle.Right;
SrcImage->Picture->Bitmap->Height= MRectangle.Bottom;
SrcImage->Picture->Bitmap->Canvas->CopyRect( MRectangle, ScreenCanvas,
ScreenCanvas->ClipRect );
delete ScreenCanvas;
ReleaseDC( hSomeWindow, dc );
Here is my second question. Should I in this case take care of
how TImage object was filled with data because of assigning:
SrcImage->Picture->Bitmap->Assign( DstImage->Picture->Bitmap )
In these two cases I loaded image into SrcImage the two different ways,
so should I keep track of how I got data because of latter assigning.
Vladimir.
P. S. Sorry for my bad English (and worse VCL C++ :)
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun Jan 25, 2004 10:36 pm Post subject: Re: Some questions about TImage... |
|
|
"Vladimir Stefanovic" <spam (AT) not (DOT) needed> wrote
| Quote: | Should I always use:
SrcImage->Picture->Assign( DstImage->Picture );
|
Yes, except that you have it backwards. You are assigning the DstImage to
the SrcImage instead of the other way around:
DstImageSrcImage->Picture->Assign( SrcImage->Picture );
Or simply:
DstImage->Picture = SrcImage->Picture;
Which calls Assign() internally.
| Quote: | or, depending of a file type (*.bmp, ...)
SrcImage->Picture->Bitmap->Assign( DstImage->Picture->Bitmap );
|
No. As soon as you reference the Bitmap property for any reason whatsoever,
the contained image will be converted to a bitmap. Thus you will lose your
original image format.
| Quote: | TRect MRectangle = ScreenCanvas->ClipRect;
|
If you are trying to get the dimensions of the window, use the
GetWindowRect() function instead:
RECT MRectangle;
::GetWindowRect(hSomeWindow, &MRectangle);
| Quote: | MRectangle.Right = MRectangle.Right - MRectangle.Left;
MRectangle.Bottom = MRectangle.Bottom - MRectangle.Top;
|
That code has no effect. You set the Left and Top values to 0 beforehand,
so those statements are the same as the following:
MRectangle.Right = MRectangle.Right - 0;
MRectangle.Bottom = MRectangle.Bottom - 0;
aka:
MRectangle.Right = MRectangle.Right;
MRectangle.Bottom = MRectangle.Bottom;
Thus, you are assigning the same values back to themselves without any
change.
Try this code instead:
HDC hdc = NULL;
Graphics::TCanvas *ScreenCanvas = new Graphics::TCanvas;
try
{
hdc = GetDC( hSomeWindow );
ScreenCanvas->Handle = hdc;
RECT r;
GetWindowRect( hSomeWindow, &r );
Graphics::TBitmap *bmp = SrcImage->Picture->Bitmap;
bmp->Width = (r.right - r.left);
bmp->Height = (r.bottom - r.top);
bmp->Canvas->CopyRect( r, ScreenCanvas, r );
}
__finally
{
if( hdc )
ReleaseDC( hSomeWindow, hdc );
delete ScreenCanvas;
}
| Quote: | Should I in this case take care of how TImage object was
filled with data because of assigning:
SrcImage->Picture->Bitmap->Assign( DstImage->Picture->Bitmap )
|
For what purpose exactly? Please elaborate. You shouldn't really care how
the TImage is being loaded, it is making a copy of the image data either
way. Once loaded, the data is separate from whatever source it came from.
Gambit
|
|
| 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
|
|