D2009 introduces PNG support for Images and Imagelists.
However...
I have an imagelist containing png images with alpha. I want to place one of these on a form using a TImage. How do I do this and get the image nicely composited?
As an example of the problem I'm facing the code below fails to work correctly, and produces the effect shown:
ImageList.GetBitmap(index, Image1.Picture.Bitmap);
(source: clip2net.com)
To explain a bit more:
Drop a Timage on a form, and at design time, load a PNG file with alpha using the Picture property. Note how it is correctly composited with full transparency onto the form.
Now, at design time, add a second empty Timage, add a TImagelist, and add the same PNG to the imagelist. How can I assign the PNG in the TImageList to the second TImage, and have it look identical to the first one?
From my research I found that TImageList stores the images as TBitmaps, so the alpha information is lost on storage, and you can't achieve what you're looking for with the current implementation of TImageList.
Update:
A little more experiments and with the code below i could make transparency work with the code below.
ImageList1.ColorDepth := cd32Bit;
Image2.Transparent := True;
Image2.Canvas.Pen.Style := psClear;
Image2.Canvas.Rectangle(0, 0, Image2.Width+1, Image2.Height+1);
ImageList1.Draw(Image2.Canvas, 0,0,0);
But it didn't look as pretty as a loaded png.