[Lazarus] Create transparency

Marc Weustink marc at dommelstein.net
Mon Jul 21 23:02:27 CEST 2008

Valdas Jankūnas wrote:
> Marc Weustink rašė:
>> A faster way, (which might work in most cases) is when you have a 24bit 
>> depth description with a 32bits per pixel image. 
>   How retrieve image description from TBitmap?


>> Then you can simply add 
>> an alpha description (precision=8, shift=24 or 0) to the rawimage.
>   How i can do that?

if Description.BitsPerPixel = 32
then begin
   if  (Description.RedShift <> 0)
   and (Description.BlueShift <> 0)
   and (Description.GreenShift <> 0)
   then begin
     Description.AlphaPrec := 8;
     Description.AlphaShift := 0;
   if  (Description.RedShift <> 24)
   and (Description.BlueShift <> 24)
   and (Description.GreenShift <> 24)
   then begin
     Description.AlphaPrec := 8;
     Description.AlphaShift := 24;

>> Another thing, I'm not sure if loading form IntfImage/RawImage sets the 
>> right pixelformat (and thus image description).
>> Anyway, maybe the bmp is OK. How do you paint it ?
>   I use Canvas.Draw method.

Bmp.Canvas.Draw(bitmap) draws in the dept of bmp and not the depth of 
bitmap. This means if bmp is only created it has pixelformat=pfDevice. 
Currently that creates a context(and canvas) without alpha channel)

> I found another solution to not use a proxy image, but load resource 
> from stream directly to LazIntfImage (created with 
> Init_BPP32_B8G8R8A8_BIO_TTB description). Now i always got alpha channel 
> and code is flexible to various image types (need just change image 
> reader type). I thing il stay with this solution.

Thats ways faster.


More information about the Lazarus mailing list