Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to copy transparent (32-bit) PNG image from TImageList into TImage?

4,061 views
Skip to first unread message

John

unread,
Jun 27, 2010, 8:41:30 PM6/27/10
to
What I want is to copy TImageList 32-bit PNG image (with alpha transparency)
to blank TImage.

ImageList1 contains 32-bit PNG images. Image1 is just a blank TImage.

I tried it like this and this works but it copies it as icon:

ImageList1.GetIcon(0, Image1.Picture.Icon);

Is there an other way to copy it as transparent PNG? Assign or something?


Skybuck Flying

unread,
Jun 29, 2010, 2:59:12 PM6/29/10
to

"John" <jo...@my.com> wrote in message news:i08r6e$vn2$1...@gregory.bnet.hr...

Did you try to find/seek the image in the imagelist and then draw it to the
other image something like:

Image1.Picture.Bitmap.Canvas.Draw( 0, 0,
ImageList[?].Image.Picture.Bitmap );

^ Something like that... try image then image.picture then
image.picture.bitmap

Bye,
Skybuck.


John

unread,
Jul 2, 2010, 1:13:19 PM7/2/10
to
> Did you try to find/seek the image in the imagelist and then draw it to
> the other image something like:
>
> Image1.Picture.Bitmap.Canvas.Draw( 0, 0,
> ImageList[?].Image.Picture.Bitmap );
>
> ^ Something like that... try image then image.picture then
> image.picture.bitmap

That doesn't work with transparent PNG's but only for single-color
background. The only way I found so far is by changing image type to Icon
and copying icon like I specified in my original post...


John

unread,
Jul 2, 2010, 1:24:55 PM7/2/10
to
> Image1.Picture.Bitmap.Canvas.Draw( 0, 0,
> ImageList[?].Image.Picture.Bitmap );

and there is no ImageList[n] nor Image.Picture.Bitmap...


Jamie

unread,
Jul 2, 2010, 7:54:08 PM7/2/10
to
Have you tried using the "AddMasked" Image of the TImageList? That will
allow you to use the "DRAW" of the Timagelist to the destination object
which will show a transparent image.. In other words, you can keep the
image in the list and use it's "DRAW" member to actually update any
visual view of it on the screen or, some bitmap if you wish.., You
simply specify what the transparent color is in the image when you store
the image in the list..

If you do not want to do that, you can move it to a bitmap or timage
or what ever and later on use the "CANVAS.BRUSHCOPY" to display it as
transparent..

etc..

Jamie.

Skybuck Flying

unread,
Jul 3, 2010, 6:16:32 PM7/3/10
to
Try something like this:

ImageList1.Draw( Image1.Canvas, 0, 0, 0, dsTransparent, itImage );
ImageList1.Draw( Image1.Canvas, x, y, index, dsTransparent, itImage );

This draws the indexed image in imagelist to image1.

Consult help for further details but I am guessing you don't have the help ?

Bye,
Skybuck.


John

unread,
Jul 5, 2010, 8:28:25 AM7/5/10
to
> ImageList1.Draw( Image1.Canvas, 0, 0, 0, dsTransparent, itImage );
> ImageList1.Draw( Image1.Canvas, x, y, index, dsTransparent, itImage );

sorry, this will work only on tbitmap images not on PNG.

again, i'm talking about 32-bit alpha-channel PNGs. not bitmaps, not single
transparent color but with 8-bit transparent color (alpha channel,
256-"shades" of transparency).

why don't you simply try examples you post here? create imagelist and image
on the form, put simply 32-bit png into imagelist and try to copy it as
transparent as it is to the timage. take for example this 32-bit png:
http://www.freeiconsweb.com/Freeicons/256x256_Transparent_Icons2/27.png

the only way i found so far is:

ImageList1.GetIcon(0, Image1.Picture.Icon);

which assigns embedded graphic (png in this case) as icon (which can also be
transparent) to the image1. image1 graphic then changes into ticon type but
that's fine with me. what i was asking is if there is another way that would
assign png to keep the image1.picture.graphic as PNG.

this might work:

Image1.Picture.Graphic.Assign();

but i need TPersistent pointer to the graphic of TimageList and graphic
property in image list is inaccesible directly.
the only way i can get something out of imagelist that i found is through
"Get" methods. GetBitmap is useless so I need something else that retrieves
it as PNG or as Graphic pointer to a specific image in the list.

> This draws the indexed image in imagelist to image1.
> Consult help for further details but I am guessing you don't have the help
> ?

of course i have the help. been looking on it and on online help and
googling... a lot! i didn't ask question before heavily searching into it.


Skybuck Flying

unread,
Jul 5, 2010, 6:00:39 PM7/5/10
to
I am kinda low on time at the moment.

I looked at an example in Delphi 2007, in 2007 TImageList does not support
PNG it seems.

So you must be using a higher version of Delphi, perhaps 2009 or 2010 ?

I don't like those versions... so for now you on your own :)

Maybe in the future I might change my mind but don't bet on it ;)

I do have 2010 installed... maybe later I will take a look what you babbling
about...

Bye,
Skybuck.


John

unread,
Jul 6, 2010, 11:10:50 AM7/6/10
to
> I do have 2010 installed... maybe later I will take a look what you
> babbling about...

well, all i can say is that 2009/2010 are A LOT better than 2007 and have
full unicode support but also a lot of other things. 2006 and 2007 were
transition versions where features were half-implemented unlike 2009/2010
versions.

anyway, try it when you have time it's no rush, GetIcon() is already working
but... there may be a better way.

timagelist supports PNGs in 2009/2010.


Skybuck Flying

unread,
Jul 6, 2010, 11:39:04 AM7/6/10
to

"John" <jo...@my.com> wrote in message news:i0vh2m$s70$1...@gregory.bnet.hr...

>> I do have 2010 installed... maybe later I will take a look what you
>> babbling about...
>
> well, all i can say is that 2009/2010 are A LOT better than 2007 and have

2009/2010 has certain improvements but those same improvements could also
cause problems and break backwardscompatibility.

> full unicode support but also a lot of other things. 2006 and 2007 were

Unicode support is one of those things which could break backwards
compatibility for lot's of code which deals with strings
and which made certain assumptions.

> transition versions where features were half-implemented unlike 2009/2010
> versions.

At least 2007 can still compile for windows 95 and work on it... not so with
2009/2010.

Again backwards compatibility goes out the window with 2009/2010.

> anyway, try it when you have time it's no rush, GetIcon() is already
> working but... there may be a better way.

Tell you what... you provide me with an "alpha" png image and try to explain
what it is you want to do because it's not completely clear to me...

It sounds to me like you are trying to do some form of blending... like
alpha blending.

Furthermore why are you trying to use TImageList, why not some other form of
list ?

TImageList seems to be mostly limited to icons and such... it doesn't seem
to support large resolution pictures ?!?

Are you cool/fine with that ? Are you trying to draw just icons ? Or do you
want to draw large resolution pictures as well ?

You might want to check out "graphics 32"

http://graphics32.org/wiki/

It's a library which supports 32 bit images and alpha blending if I am
correct ;) :)

Another library you might wanna check out is:

http://www.angusj.com/delphi/gr32_lines.php

I haven't actually used these libraries so I have no experience with it, and
I don't know if it's easy to use... but they claim that it is.

You might have more like with that.

Alternatively you could simply allocate an array of Timage and do the alpha
blending with some code yourself... it might be a bit slower though...

> timagelist supports PNGs in 2009/2010.

I see ;)

Bye,
Skybuck.


Skybuck Flying

unread,
Jul 6, 2010, 11:40:15 AM7/6/10
to
Oh I see you provided an example png in previous post..

I'll check it out and I'll get back to you on it ;) :)

(I thought the link was to my own message hihi)

Bye,
Skybuck.


Skybuck Flying

unread,
Jul 6, 2010, 12:32:18 PM7/6/10
to
Two solutions:

1. The stupid/work around solution:

However Delphi 2010 does have TPngImage... that might be of some use:

uses
Pngimage;

procedure TForm1.Button1Click(Sender: TObject);
begin
mImage := TPngImage.Create;

mImage.LoadFromFile( '... path to picture goes here...');

mImage.Draw( Form1.Canvas, Rect(10,10,100,100) );

mImage.Free;
end;

So what you could do... is first draw the picture from the TimageList to a
TPNGImage... then draw the TPNGImage to whatever it is you want to draw it.

There could be a direct way to though... if the image stored inside
TImageList is of class TPNGImage...

Then perhaps it could be retrieved... perhaps typecasted etc.

2. The easy solution:

Set ColorDepth to 32 bit like so:

ImageList1.ColorDepth := cd32Bit;

Then load images...

Then simple draw images like so:

ImageList1.Draw( Form1.Canvas, 0,0,0 );

ColorDepth is in the properties as well so it can be changed in the property
editor.

Then after you change it to cd32bit you will need to reload any images.

Then you should be able to do alpha blending just fine !

Good luck,
Bye,
Skybuck.


Skybuck Flying

unread,
Jul 6, 2010, 12:34:45 PM7/6/10
to
This works for drawing from TImageList to TImage as well:

ImageList1.Draw( Image1.Canvas, 0,0,0 );

All you need to do is set ImageList1.ColorDepth to cd32bit in the property
editor, then load any images via property editor if you wish too... or do it
programmatically in code...

(after changing colordepth all images are removed from the TimageList so you
will have to reload them).

Bye,
Skybuck.

John

unread,
Jul 7, 2010, 4:06:58 PM7/7/10
to
> ImageList1.Draw( Image1.Canvas, 0,0,0 );

alright! now, that's what helpful! thanks... a lot!

there could however be a problem. if you use draw to draw onto image1 canvas
it will draw it against single-colored background. so you simply fill the
background prior to drawing it will draw it correctly (alpha-blended etc.).
but if background is not uniformly colored - where with PNG image that
shouldn't be an issue. but that's a whole other topic.


John

unread,
Jul 7, 2010, 4:08:04 PM7/7/10
to
> mImage.LoadFromFile( '... path to picture goes here...');

well, better thing here is to load it from resource which are embedded in
application. but i wanted to avoid resources and use imagelist instead.


0 new messages