BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TBitmap descendant and Assign

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Roddy Pratt
Guest





PostPosted: Wed Jul 28, 2004 11:13 pm    Post subject: TBitmap descendant and Assign Reply with quote



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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.