我正在尝试将PNG文件添加到TPngImageList (从http://code.google.com/p/cubicexplorer/downloads/list获得的D7的PngComponents )。
type
TImgListCrack = class(TPngImageList);
function LoadPngIconEx(ImageList: TPngImageList; const fn: string): boolean;
var
Icon: HICON;
AImage: TPngObject;
begin
with ImageList do
begin
BeginUpdate;
try
AImage:= TPngObject.Create;
AImage.LoadFromFile(fn);
Icon:= TImgListCrack(ImageList).PngToIcon(AImage);
ImageList_AddIcon(Handle, Icon);
DestroyIcon(Icon);
FreeAndNil(AImage);
Result:= true;
finally
EndUpdate;
end;
end;
end;结果:未添加图标,imagelist仍为空。怎么做好吗?
发布于 2013-06-19 21:30:57
没有经过测试,但这不应该简单地工作吗?
ImageList.PngImages.Add.PngImage.LoadFromFile(fn);发布于 2013-06-19 21:55:25
使用PngImageList的其他方法解决。Prop PngImages具有所需的功能。
function LoadPngIconEx(ImageList: TPngImageList; const fn: string): boolean;
var
AImage: TPngObject;
begin
if not FileExists(fn) then
Result:= false
else
begin
AImage:= TPngObject.Create;
try
AImage.LoadFromFile(fn);
ImageList.PngImages.Add.PngImage:= AImage;
Result:= true;
finally
FreeAndNil(AImage);
end;
end;
end;https://stackoverflow.com/questions/17192142
复制相似问题