This blog is a personal outlet to share some things I encounter during my coding adventures and would like to share with the world, so that others (hopefully) can profit by it.

This blog does not express in any way the views and opinions of the companies I work for!

Happy reading and of course leave your comments where you see fit!

dinsdag 18 september 2007

PngComponents - Adding images to a list in code

The PngComponents suite of Martijn Saly is awsome and adds excellent Png support to the Delphi programming environment. For example the imagelist component (TPngImageList) mimics the original Delphi VCL imagelist so that you can use Png images in any component supporting the standard imagelist, like treeviews, listviews etc.

The architecture around the Png imagelist is however a bit different than that of Delphi, and may lead to confusion, especially when trying to access it from code.
This article shows you how to use and manipulate the Png imagelist from code..


Update: New Delphi versions (from 2009) offer PNG out of the box, in which case you manipulate the TImageList instead of TPngImageList. In that case the info in this post is deprecated.



FImages: TPngImageList; // example var with imagelist, for the example sake we suppose its already created

procedure AddPng(aPngImage: TStream);
var
col: TImageCollectionItem;
imgcol: TPngImageCollection;
begin
imgcol := TPngImageCollection.Create(nil);
imgcol.Items.Assign(FImages.PngImages);
col := imgcol.Items.Add;
aPngImage.Position := 0;
col.PngImage.LoadFromStream(aPngImage);
FImages.Width := col.PngImage.Width;
FImages.Height := col.PngImage.Height;
ItemHeight := FImages.Height + 2;
FImages.PngImages.Assign(imgcol.Items);
col.Name := 'PngImage' + IntToStr(FImages.PngImages.Count - 1);
end;

Geen opmerkingen:

Een reactie posten

Labels