PNG in Delphi 2009 Imagelists and Images

D2009 introduces PNG support for Imagelists images and images.

But...

I have an imagelist containing png images with alpha. I want to place one of them in a form using TImage. How can I do this and get an image beautifully composed?

As an example of the problem that I encountered, the code below does not work correctly and gives the shown effect:

ImageList.GetBitmap(index, Image1.Picture.Bitmap); 

alt text http://clip2net.com/clip/m0/1234439882-clip-5kb.png

Explain a little more:

Drop the timeline onto the form and during development upload the PNG file with alpha using the "Image" property. Pay attention to how it is correctly generated with full transparency in the form.

Now, during development, add a second empty Timage, add a TImagelist and add the same PNG to the imagelist. How can I assign a PNG in a TImageList to a second TImage and look identical to the first?

+4
source share
6 answers

From my research, I found that TImageList stores images in the form of TBitmaps, so alpha information is lost during storage, and you cannot achieve what you are looking for with the current implementation of TImageList.

Update:

A little more experimentation 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 the downloaded png.

+4
source

Check the "Enable runtime" checkbox on the tab on the Project → Settings → application tab

This solved my problem for me in RAD Studio 2010.

+2
source

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

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

It was important for me to set img2.Transparent: = true (I used the constructor, not the code).

+1
source

I came across this thread discussion:

Transparent PNG to D2009 TImageList

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

I do not have access to delphi 2009 my self, so I have not tried it, though ...

+1
source

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

Using AddMasked or InsertMasked you add an image and add color to a transparent color:

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

Using Insert or Add you add an image and a mask. Mask, if a 2-color (black and white) image, where only white pixels of the image are used, the rest are transparent.

 function Add(Image, Mask: TBitmap): Integer; procedure Insert(Index: Integer; Image, Mask: TBitmap); 
0
source

As far as I know, this cannot be achieved. None of the above suggestions lead to the correct alpha mixed image, which is the basic requirement.

Perhaps by defining a class derived from TImageList, which could then access protected methods, something could be made to work. My solution at the moment is to specifically use a third-party custom ImageList component for it.

0
source

All Articles