Recent

Author Topic: ImageList to Image // 32bit (images with alpha channel, tested on PNG)  (Read 3252 times)

adc

  • New Member
  • *
  • Posts: 12
Hi folks,
 
   i don't know if this have been solved (i couldn't find it) so here goes. I couldn't copy 32bit PNG image from ImageList to empty Image created on the form and preserve transparency. It seems that Picture.Bitmap.Width & Height properties aren't properly initialized when new Timage is put on form.
That is, i think they don't get correct values from "IDE inspector" and 'couse of that Timage don't respond properly. If you however load a picture into Timage (on the form) everything works.

So, i solved it this way...probably there is a better way to do it,  still, hope it helps.
Just "send your image" to this procedure before copying from ImageList to Image and you'll have transparency of your original image in ImageList.

I am using v2.6.4 of FPC and 1.4.4 of Lazarus on Yosemite 10.10.5 ( running on PC ; )


procedure TForm1.InitImage(Sender: TObject);
begin
 with Sender as TImage do
  begin
    Picture.Bitmap.Width:=(Sender as Timage).Width;
    Picture.Bitmap.Height:=(Sender as Timage).Height;
    Picture.Bitmap.canvas.Brush.Style := bsClear;
    Picture.Bitmap.canvas.FillRect(Rect(0, 0, (Sender as Timage).Width, (Sender as Timage).Height));
    Picture.Bitmap.PixelFormat:=pf32bit;
    Picture.Bitmap.Transparent:=true;
    Picture.Bitmap.TransparentMode:=tmAuto;
  end                                                 
end;               

don't forget to declare procedure & enjoy your Timages with transparency (;

Note to Admins: once again guys, i am sorry if this is been resolved and i am totally oblivious.

Best Regards,

M.



 
« Last Edit: December 13, 2015, 08:01:31 pm by adc »

 

TinyPortal © 2005-2018