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

Load PNG images from Resource into ImageList

1,971 views
Skip to first unread message

Michael Fritz

unread,
Jun 27, 2007, 3:24:44 AM6/27/07
to
Hi,

I'm trying to load PNG images from a resource file into an imagelist.

The rc file looks like this and compiles well into an res file:
IDR_BLANK RCDATA ".\..\img\blank.png"
IDR_FLAGRED RCDATA ".\..\img\flag_red.png"
IDR_FLAGYELLOW RCDATA ".\..\img\flag_yellow.png"
IDR_FLAGGREEN RCDATA ".\..\img\flag_green.png"
IDR_FLAGBLUE RCDATA ".\..\img\flag_blue.png"
IDR_FLAGORANGE RCDATA ".\..\img\flag_orange.png"
IDR_FLAGPINK RCDATA ".\..\img\flag_pink.png"
IDR_FLAGPURPLE RCDATA ".\..\img\flag_purple.png"
IDR_COMMENT RCDATA ".\..\img\comment.png"
IDR_COMMENTS RCDATA ".\..\img\comments.png"

I tried to load those images using this coding:
FImageList.ResInstLoad(HInstance, rtBitmap, 'IDR_BLANK', clLime);

But it seems that no images are present, at least my listview doesn't show
any. Is this due to the fact the imagelist cannot handle PNG images?
--
cu,
Michael

matthias muntwiler

unread,
Jun 27, 2007, 10:44:29 AM6/27/07
to
Michael Fritz wrote:
> I tried to load those images using this coding:
> FImageList.ResInstLoad(HInstance, rtBitmap, 'IDR_BLANK', clLime);
>
> But it seems that no images are present, at least my listview doesn't show
> any. Is this due to the fact the imagelist cannot handle PNG images?

if you ask for rtBitmap, the resource type must be BITMAP, not RCDATA.
but that won't help you with PNG files because the image list cannot
handle them.

you need to load the PNG resources yourself using a TPngImage (e.g. from
pngimage.sf.net) and convert it to a bitmap before adding it to the
list. alternatively, you could use TPngImageList from
www.thany.org/article/32/PngComponents.

--matthias

Mat Ballard

unread,
Jun 27, 2007, 7:26:26 PM6/27/07
to
Michael Fritz wrote:

> I'm trying to load PNG images from a resource file into an imagelist.
>
> The rc file looks like this and compiles well into an res file:
> IDR_BLANK RCDATA ".\..\img\blank.png"

> ...


>
> I tried to load those images using this coding:
> FImageList.ResInstLoad(HInstance, rtBitmap, 'IDR_BLANK', clLime);

They are not bitmaps - they are PNGs. So you need to create a PNG, load the PNG
from resource, then transfer to ImageList:

PNG := TPngObject.Create;
PNG.LoadFromResourceID(...);

ABitmap.Assign(PNG);
FImageList.Add(ABoitmap, nil);

0 new messages