Albert wrote:
As you can see the resized images are 'messed up' but I don't
know why.
Your images are overlapping because you are not resetting the intermediate
TBitmap objects on each loop iteration. You are drawing new images on top
of old images. TImageList::GetBitmap() and TBitmap::StretchDraw() do not
erase a TBitmap, they simply draw on top of whatever is already on the TBitmap.
So your loop need to either:
1) destroy+recreate the TBitmap objects on each iteration:
void AWDPI_Scale_TImageList(TImageList *images)
{
const int width(2*images->Width), height(2*images->Height);
TRect R(0,0,width,height);
TImageList *newimages(new TImageList(NULL));
newimages->Height=height;
newimages->Width=width;
const size_t numimages(images->Count);
for (size_t i(0); i < numimages; ++i)
{
TBitmap *src(new TBitmap);
src->PixelFormat=pf32bit;
images->GetBitmap(i,src);
TBitmap *dest(new TBitmap);
dest->Height=height;
dest->Width=width;
dest->Canvas->StretchDraw(R,src);
newimages->Add(dest,NULL);
delete dest;
delete src;
}
images->Assign(newimages);
delete newimages;
}
2) resize the TBitmaps to 0x0 dimensions to clear them, then resize them
back to the proper size when drawing:
void AWDPI_Scale_TImageList(TImageList *images)
{
const int width(2*images->Width), height(2*images->Height);
TRect R(0,0,width,height);
TImageList *newimages(new TImageList(NULL));
newimages->Height=height;
newimages->Width=width;
TBitmap *dest(new TBitmap);
TBitmap *src(new TBitmap);
src->PixelFormat=pf32bit;
const size_t numimages(images->Count);
for (size_t i(0); i < numimages; ++i)
{
src->Height=0;
src->Width=0;
dest->Height=0;
dest->Width=0;
images->GetBitmap(i,src);
dest->Height=height;
dest->Width=width;
dest->Canvas->StretchDraw(R,src);
newimages->Add(dest,NULL);
}
images->Assign(newimages);
delete src;
delete dest;
delete newimages;
}
3) draw a background to erase the TBitmap objects without having to resize
them:
void AWDPI_Scale_TImageList(TImageList *images)
{
const int srcWidth(images->Width), srcHeight(images->Height);
const int dstWidth(2*srcWidth), dstHeight(2*srcHeight);
TRect srcR(0,0,srcWidth,srcHeight);
TRect dstR(0,0,dstWidth,dstHeight);
TImageList *newimages(new TImageList(NULL));
newimages->Height=dstHeight;
newimages->Width=dstWidth;
TBitmap *dest(new TBitmap);
dest->Height=dstHeight;
dest->Width=dstWidth;
TBitmap *src(new TBitmap);
src->PixelFormat=pf32bit;
const size_t numimages(images->Count);
for (size_t i(0); i < numimages; ++i)
{
images->GetBitmap(i,src);
dest->Canvas->StretchDraw(dstR,src);
newimages->Add(dest,NULL);
src->Canvas->Brush->Color = ...;
src->Canvas->FillRect(srcR);
dest->Canvas->Brush->Color = ...;
dest->Canvas->FillRect(dstR);
}
images->Assign(newimages);
delete src;
delete dest;
delete newimages;
}
--
Remy Lebeau (TeamB)
Connect with Us