Delphi XE 支持处理 png 图像和带有 alpha 通道的 32 位位图。以下是将 png 添加到 ImageList 的方法:
uses CommCtrl;
var pngbmp: TPngImage;
bmp: TBitmap;
ImageList: TImageList;
begin
ImageList:=TImageList.Create(Self);
ImageList.Masked:=false;
ImageList.ColorDepth:=cd32bit;
pngbmp:=TPNGImage.Create;
pngbmp.LoadFromFile('test.png');
bmp:=TBitmap.Create;
pngbmp.AssignTo(bmp);
// ====================================================
// Important or else it gets alpha blended into the list! After Assign
// AlphaFormat is afDefined which is OK if you want to draw 32 bit bmp
// with alpha blending on a canvas but not OK if you put it into
// ImageList -- it will be way too dark!
// ====================================================
bmp.AlphaFormat:=afIgnored;
ImageList_Add(ImageList.Handle, bmp.Handle, 0);
您必须包括
图像列表,PngImage
如果您现在尝试:
Pngbmp.Draw(Bmp1.Canvas,Rect);
and
ImageList.Draw(Bmp1.Canvas,0,0,0,true);
你会看到图像是一样的。实际上,由于 alpha 混合期间的舍入误差,存在一些 \pm 1 rgb 差异,但您无法用肉眼看到它们。忽略设置 bmp.AlphaFormat:=afIgnored; 会导致第二张图像更暗!
最好的祝福,
亚历克斯