Recent

Author Topic: [Solved] Get transparent png from TImageList  (Read 129 times)

nikel

  • Sr. Member
  • ****
  • Posts: 282
[Solved] Get transparent png from TImageList
« on: June 04, 2026, 08:39:59 am »
Hello, I'm trying to access the TImageList (Buttons_Iml) which I created on IDE. Parent of my TImage (AddUrl_Img) is a TPanel. The code below is in Form's OnCreate event. Here's my code so far:
Code: Pascal  [Select][+][-]
  1. with Buttons_Iml do
  2. begin
  3.   {ColorDepth:=cd32Bit;
  4.   DrawingStyle:=dsTransparent; <-- These are giving me error, I commented in}
  5.   Scaled:=True;
  6.   ShareImages:=True;
  7. end;
  8.  
  9. AddUrl_Img.Refresh;
  10. with AddUrl_Pnl do
  11. begin
  12.   Caption:='';
  13.   OnMouseDown:=@MouseDownHandler;
  14.   OnMouseUp:=@MouseUpHandler;
  15. end;
  16. with AddUrl_Img do
  17. begin
  18.   Images:=Buttons_Iml;
  19.   Anchors:=[akLeft,akRight];
  20.   Center:=True;
  21.   Stretch:=True;
  22.   Proportional:=True;
  23.   Transparent:=True;
  24.   ImageIndex:=0;
  25.   Width:=80;
  26.   Height:=80;
  27.   with Images do
  28.   begin
  29.     Width:=80;
  30.     Height:=80;
  31.     Scaled:=True;
  32.   end;
  33. end;
  34. // Buttons_Iml.GetIcon(0, AddUrl_Img.Picture.Icon); <-- This displays blank panel
  35. Buttons_Iml.Draw(AddUrl_Img.Canvas, 0, 0, 0); // <-- This displays black rectangle
  36. ShowMessage(Buttons_Iml.ToString + ' ' + Buttons_Iml.Count.ToString);
  37. AddUrl_Img.Refresh;
  38. AddUrl_Lbl.Caption:='Add URL';

How can I correctly display the transparent png?
« Last Edit: June 04, 2026, 11:52:02 am by nikel »

paweld

  • Hero Member
  • *****
  • Posts: 1638
Re: Get transparent png from TImageList
« Reply #1 on: June 04, 2026, 11:19:23 am »
use:
Code: Pascal  [Select][+][-]
  1. Buttons_Iml.GetBitmap(0, AddUrl_Img.Picture.Bitmap);
instead of
Code: Pascal  [Select][+][-]
  1. Buttons_Iml.Draw(AddUrl_Img.Canvas, 0, 0, 0);
Best regards / Pozdrawiam
paweld

hedgehog

  • Full Member
  • ***
  • Posts: 121
Re: Get transparent png from TImageList
« Reply #2 on: June 04, 2026, 11:26:38 am »
Here's another little demo

nikel

  • Sr. Member
  • ****
  • Posts: 282
Re: Get transparent png from TImageList
« Reply #3 on: June 04, 2026, 11:51:40 am »
Those helped a lot. Thanks for the replies.

Xenno

  • Full Member
  • ***
  • Posts: 109
    • BS Programs
Re: [Solved] Get transparent png from TImageList
« Reply #4 on: June 04, 2026, 12:00:43 pm »
To get transparent image from TImageList, we can get is as icon.

Code: Pascal  [Select][+][-]
  1. var
  2.   ico: TIcon;
  3. ...
  4.   ico := TIcon.Create;
  5.   try
  6.     Buttons_Iml.GetIcon(imgIndex, ico);
  7.     AddUrl_Img.Picture.Assign(ico);
  8.   finally
  9.     ico.Free;
  10.   end;    
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

 

TinyPortal © 2005-2018