How to load a transparent Image from ImageList?

Martin Melka picture Martin Melka · Jul 22, 2012 · Viewed 21.1k times · Source

I want to load a picture (32 bit-depth, transparent) from a TImageList to an TImage. The standard approach would be ImageList.GetBitmap(Index, Image.Picture.Bitmap);. However the GetBitmap method doesn't work with transparency, so I always get a non-transparent bitmap.

Answer

Martin Melka picture Martin Melka · Jul 22, 2012

The workaround is rather simple - ImageList offers another method, GetIcon, which works OK with transparency. Code to load a transparent Image would be:

ImageList.GetIcon(Index, Image.Picture.Icon);

And don't forget to set proper ImageList properties:

ImageList.ColorDepth:=cd32bit;
ImageList.DrawingStyle:=dsTransparent;