Roddy Pratt Guest
|
Posted: Wed Jul 28, 2004 11:13 pm Post subject: TBitmap descendant and Assign |
|
|
I have a weird problem with a class (TDIB) I've written which is derived
from TBitmap.
Basically, I have a few extra fields (title, aspect ratio, etc) and a few
additional methods, but it's still the same TBitmap underneath.
Now, I have a halftone 'resize' method which calls StretchBlt.. which is
something like this...
SetStretchBltMode(dest->Canvas->Handle,HALFTONE);
SetBrushOrgEx(dest->Canvas->Handle,0,0,NULL);
StretchBlt(dest->Canvas->Handle, 0,0, dest->Width, dest->Height,
Canvas->Handle, 0, 0, Width, Height, SRCCOPY);
Normally, this all works just fine. I've had this in production code for
almost a year. But today, I found this method causing really bad contouring
and corruption in the resized image - the original bitmap is fine and
uncorrupted, but the resized one is shot to hell. No error is returned.
What's changed is that I'm now "Assign"ing the bitmap to a second TDIB
after loading it, like this:-
TBitmap *d1 = new TDIB;
TBitmap *d2 = new TDIB;
d1->LoadFromFile("fred.bmp");
d2->Assign(d1);
d1->Resize(); // This works OK every time
....
d2->Resize(); // This fails intermittently. sometimes it's fine, sometimes
it's rubbish.
My thoughts are that either my Assign method is broken - but it just looks
like this:-
void __fastcall TDIB::Assign(TPersistent *Source)
{
TDIB *pDib = dynamic_cast<TDIB*>(Source);
if(pDib != NULL)
{
// copy over additional fields...
}
inherited::Assign(Source);
}
... or, that my "Resize" method is not correct due to the way the reference
counting operates. Is there something subtle I should do before using the
Canvas->Handle property with a GDI routine??
Thanks,
- Roddy
|
|