2

PNGファイルをTPngImageListに追加しようとしています(D7のPngComponentsはhttp://code.google.com/p/cubicexplorer/downloads/listから取得しました)。

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;

結果: アイコンは追加されず、イメージリストはまだ空です。どうしたらいいの?

4

2 に答える 2

2

テストされていませんが、それは単に機能するべきではありませんか?

ImageList.PngImages.Add.PngImage.LoadFromFile(fn);
于 2013-06-19T13:30:57.233 に答える
0

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;
于 2013-06-19T13:55:24.977 に答える