I need add in runtime a png image to a TImageList
. I've looked at the functions implemented by the TCustomImageList
but they only allow adding
- bitmaps,
- icons or
- images from another imagelist
E.g.:
function Add(Image, Mask: TBitmap): Integer;
function AddIcon(Image: TIcon): Integer;
function AddImage(Value: TCustomImageList; Index: Integer): Integer;
procedure AddImages(Value: TCustomImageList);
function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
How I can add a PNG image to a ImageList component without converting this image to BMP?
The IDE already can add a PNG to an ImageList at design time:
Now we need to do it at runtime.
Best Answer
Delphi XE has all the support to handle png images and 32-bit bitmaps with alpha channel. Here is how to add png to an ImageList:
You must include
ImgList, PngImage
If you now try:
you'll see that the images are the same. Actually, there are a few \pm 1 rgb differences due to rounding errors during alpha blending but you cannot see them with naked eye. Neglecting to set bmp.AlphaFormat:=afIgnored; would result in the second image being much darker!
Best regards,
alex