I'm trying to create and paint at runtime a 32 bit bitmap, and then add it to an ImageList. The bitmap has transparency (alpha-channel). I can create the bitmap and draw on it's Canvas with no problem, and it draws normaly with transparency over any other canvas.
The problem is when I add it to an ImageList, the image seems to lose the drawings made with the Canvas property of the bitmap.
Here is how I start the Bitmap:
Bitmap := TBitmap.Create;
Bitmap.PixelFormat := pf32bit;
Bitmap.Transparent := True;
Bitmap.AlphaFormat := afDefined;
SetBkMode(Bitmap.Canvas.Handle, TRANSPARENT);
Bitmap.SetSize(100, 42);
// now I can draw, let's say, an icon from an imagelist
ImageList.Draw(Bitmap.Canvas, 5, 5, 0, dsTransparent, itImage);
// and some other stuff
Bitmap.Canvas.RoundRect(0, 0, 99, 41, 5, 5);
Bitmap.Canvas.TextOut(50, 5, 'Test string');
If I draw this Bitmap to any control canvas, it draws normaly, with the image from the imagelist, the rounded rectangle and the text, with transparent background (anywhere that nothing was painted will be transparent; will retain the background that was already there). It means that Form1.Canvas.Draw(0, 0, Bitmap);
will draw the bitmap over the Form1 and if there was any other image there, it will be retained as background.
BUT, if I add this bitmap to an imagelist, a strange problem occurs. The ImageList has it's ColorDepth set to cd32bit, and then I call:
BitmapImageList.Width := Bitmap.Width;
BitmapImageList.Hieght := Bitmap.Height;
BitmapImageList.Add(Bitmap, nil);
Now, If I try to draw that image from imagelist with:
BitmapImageList.Draw(Form1.Canvas, 0, 0, 0);
The only thing that will be displayed is the image that was drawn in Bitmap from the ImageList, the rounded rect and the text that was drawn in the Canvas vanishes.
What am I missing?