delphipngtransparencytimagetimagelist

How to load a transparent Image from ImageList?


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.


Solution

  • 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;