Transparent bitmap (thumbnail)

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: helmut, XnTriq, xnview

Post Reply
klaus2

Transparent bitmap (thumbnail)

Post by klaus2 »

Hello,

if i transfer (in Delphi) a gfl_bmp to a bitmap and paint it using (delphi native) canvas.draw (which wraps probably TransparentStretchBlt) all works fine. But it (the TBitmap.Draw) is very slow.

If i try to use BitBlt instead, it is very fast, but the transparent part appears black.

If i use TransparentBlt instead (not available on 9x - i get 'wrong export from gdi32'), resp. equivalents of it, some .bmp, .gif and .tif are not painted very well.

Any hints pointing to the right direction about transparency are very appreciated :-)

With 2.54, the function gflSetTransparentColor is available, but there is no prototype in the libgfl.pas (proposal below), and i don't know how to use it.
Are there any usage samples (vb, c, c++, delphi ..) and is it the right answer?

Best Regards,
Klaus2

function gflSetTransparentColor(src: PGFL_BITMAP; dst: PPGFL_BITMAP;
const mask_color: PGFL_COLOR; const back_color: PGFL_COLOR): GFL_ERROR; stdcall;
klaus2

Post by klaus2 »

Hello,

i found an answer by myself, at least partially.
In so far, as i'm using more gflAutoCrops than before, with the result that there are no blacked areas in the thumbnails that need to be transparented; now the thumbnails can directly be BitBlt'ed.

By that, i gain speed on the gui side, at least when reusing thumbnails, whereas when generating thumbnails in total i loose speed due to
the additional crop operations
(and most of the images need to be cropped, in so far as normally either height or width don't fit exactly in a predefined thumbnail size,
effecting in black areas in the thumbnails).

So, my final question is: is that the correct way?
To crop the gfl_bmps for to be able to simply BitBlt the resulting bitmaps to the (windows) gui?

Many thanks and best Regards,
klaus2
MaierMan
Posts: 78
Joined: Wed Aug 04, 2004 8:32 pm
Contact:

Post by MaierMan »

TransparentBlt indeed kinda requires Win2000 or later.
See Windows Platform SDK Documentation.
Win9x implementation is there but "contains a memory leak that can exhaust system resources. To draw a transparent bitmap using BitBlt, see Knowledge Base article 79212."

But the correct wrappers should be included in Delphi as well?
Anyway...

It looks like you're generating thumbnails, but you don't want those black borders?
Not thumbnails of "transparent" pictures (as the BMP format does not contain alpha channels IIRC).
In that case you might want to add GFL_LOAD_PREVIEW_NO_CANVAS_RESIZE to your load_params.Flags ;)
klaus2

Post by klaus2 »

Hello Maierman,

yes, i did some tests with Delphi equivalents of DrawTransparentBitmap from Q79212 resp. 9x-clones of TransparentBlt, but in the last instance i had more drawbacks than benefits compared with the Delphi-built-in TBitmap.Draw (ie the memory leaks you mention).

So i had the idea avoid such overhead and to "crop" the black borders in the origin, but i was unsure if the approach itself is a good idea.

Unfortunately here i was not aware of the GFL_LOAD_PREVIEW_NO_CANVAS_RESIZE, at that point ..
Indeed it does the job, and functionally better (ie. my crop-approach strips black borders even if they are part of an image itself, and that is surely unwanted).

Many thanks for your help :-)

Best Regards,
klaus2
acsrm
Posts: 3
Joined: Mon Apr 03, 2006 6:21 am
Contact:

acsrm

Post by acsrm »

Hallo...
Now, I have the same problem. How change background color in thumbnail. Maybe small example in code ;) ?

Regards
Robert
klaus2

Post by klaus2 »

For to remove the black borders it's not necessary to change the background color of the thumbnail (means: the image itself!), but only to set the width and height of the receiving bitmap to the width and height of the source gfl_bmp.
Post Reply