Delphi - fills the image with icons at runtime "destroys" transparency

I spent hours on this (simple) and did not find a solution: /

I am using D7 and TImageList. ImageList is assigned to the toolbar. When I populate the ImageList at design time, the icons (with partial transparency) look fine. But I need to fill it at runtime, and when I do this, the icons look pretty shit - a complete loss of partial transparency.

I just tried loading the icons from the .res file - with the same result. I tried third-party image lists also unsuccessfully. I have no idea what I could do: / Thanks to everyone 2;)

Editing:

To be honest, I don’t know exactly what is going on. Alpha blending is the right term ... Here are 2 screens:

Icon added during development: alt text
(source: shs-it.de )

Icon added at runtime: alt text
(source: shs-it.de )

Your comment that alpha blending is not supported just brought a solution: I edited the image in the editor and deleted the alpha mixed pixels - and now it looks fine. But it’s still strange that the icons look different when they are added at runtime, and not at design time. If you (or someone else;) can explain this, I would be happy;) thanks for your support!

+6
delphi icons
source share
3 answers

To maintain alpha transparency, you need to create a list of images and populate it at runtime:

function AddIconFromResource(ImageList: TImageList; ResID: Integer): Integer; var Icon: TIcon; begin Icon := TIcon.Create; try Icon.LoadFromResourceID(HInstance, ResID); Result := ImageList.AddIcon(Icon); finally Icon.Free; end; end; function AddPngFromResource(ImageList: TImageList; ResID: Integer): Integer; var Png: TPngGraphic; ResStream: TStream; Bitmap: TBitmap; begin ResStream := nil; Png := nil; Bitmap := nil; try ResStream := TResourceStream.CreateFromID(HInstance, ResID, RT_RCDATA); Png := TPNGGraphic.Create; Png.LoadFromStream(ResStream); FreeAndNil(ResStream); Bitmap := TBitmap.Create; Bitmap.Assign(Png); FreeAndNil(Png); Result := ImageList.Add(Bitmap, nil); finally Bitmap.Free; ResStream.Free; Png.Free; end; end; // this could be eg in the form or datamodule OnCreate event begin // create the imagelist ImageList := TImageList.Create(Self); ImageList.Name := 'ImageList'; ImageList.DrawingStyle := dsTransparent; ImageList.Handle := ImageList_Create(ImageList.Width, ImageList.Height, ILC_COLOR32 or ILC_MASK, 0, ImageList.AllocBy); // populate the imagelist with png images from resources AddPngFromResource(ImageList, ...); // or icons AddIconFromResource(ImageList, ...); end; 
+6
source share

I had the same problems a couple of years ago. This is a Delphi problem. I ended up posting the images on the list during development, although I really didn't want to. I also had to use the DevExpress image list to get the best results and use 32-bit color images.

0
source share

As Jeremy said, this is really a Delphi limitation.

One work that I used for images that I put on buttons (PNG with alpha transparency in my case) was to store PNGs as resources, and at runtime draw them on a bitmap with the button size filled with clBtnFace. Then the bitmap was used as a control glyph.

Delphi's built-in support for alpha mask icons is very limited, however there is a great kicon icon library that can help.

0
source share

All Articles