views:

2869

answers:

6
+1  A: 

I just tried a simple test. TImageList contains a PNG image with transparency. I render the image on the second TImage using:

imlImageList.Draw(img2.Canvas, 0, 0, 0);

What made the difference for me was setting img2.Transparent := true (I used the designer, not code).

TheArtTrooper
That doesn't work for me - I get the same result as shown above. Are you sure your PNG hasd proper soft-edged transparency?
Roddy
A: 

I stumbled over this discussion-thread:

Tranparent PNGs in D2009 TImageList

@Pekka Nyyssonen: Setting ColorDepth to cd32Bit and DrawingStyle to dsTransparent worked for me.

I don't have access to delphi 2009 my self so I havn't tried it out, though...

Vegar
A: 

There are several ways to add transparent images to an image list.

With AddMasked or InsertMasked, you add an image and tags a color to be the transparent color:

procedure InsertMasked(Index: Integer; Image: TBitmap; MaskColor: TColor);
function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;

With Insert or Add, you add an image and a mask. The mask if a 2 color (black/white) image where only the white pixels from the image are used, the others are transparent.

function Add(Image, Mask: TBitmap): Integer;
procedure Insert(Index: Integer; Image, Mask: TBitmap);
Gamecat
Thanks, but I'm after proper alpha blending as the left-hand images shows, not single-bit masking, .
Roddy
+3  A: 

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.

Tiago Moraes
Nope, the alpha information isn't lost. You can use the TImagelist with TButtons and get proper transparent glyphs on the buttons. Besides, bitmaps can be 32 bpp...
Roddy
A: 

To the best of my knowledge, this cannot be acheived. None of the suggestions given result in a properly alpha-blended image, which is the primary requirement.

Maybe by defining a class derived from TImageList, which can then access protected methods, something could be got to work. My solution for now is to use a third-party custom ImageList component specifically for this.

Roddy
A: 

Check the Enable Runtime Themes in the Project ->Options ->Application tab.

This helped me in RAD Studio 2010.

Caryon