C#とVisual StudioからDelphi 10.1には非常に難しいですが、一部のパフォーマンスは非常に重要です。私はDelphiで長年(10年以上)私はブロックされています。ImageListを作成して実行時に作成する
実行時にImageListを作成してシングルトンオブジェクトに格納する必要がありますが、メモリを読み取っている間に例外が発生するため、その処理を行うことはできません。ここで
は、私のコードの抜粋である:ここ
ImagesRessource = class
private
_owner: TComponent;
_imageList: TimageList;
_man24: TPngImage;
constructor Create;
function GetBmpOf(png: TPngImage): TBitmap;
public
procedure Initialize(own: TComponent);
end;
implementation
constructor ImagesRessource.Create;
begin
;
end;
procedure ImagesRessource.Initialize(owner: TComponent);
var
bmp: TBitmap;
RS : TResourceStream;
begin
try
_man24 := TPngImage.Create;
RS := TResourceStream.Create(hInstance, 'man_24', RT_RCDATA);
_man24.LoadFromStream(RS);
bmp := GetBmpOf(_man24);
_imageList := TimageList.Create(owner);
_imageList.Width := 24;
_imageList.Height := 24;
_imageList.AddMasked(Bmp, Bmp.TransparentColor); // exception read memory here
except
raise;
end;
end;
function ImagesRessource.GetBmpOf(png: TPngImage): TBitmap;
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
bmp.Width := png.Width;
bmp.Height := png.Height;
png.Draw(bmp.Canvas, bmp.Canvas.ClipRect);
end;
何が悪いですか?
ImageListを作成し、ResourceStreamからイメージを読み取り、イメージリストに格納する必要があるのはなぜですか? ImageListをフォームまたはデータモジュールに入れ、デザイン時にイメージを追加する必要があります。 – Kohull
@Kohullを行うには、リソースを使用することが賢明です。リビジョン管理下でアセットを別のファイルに保存することができます。一旦それをdfmファイルに入れると、維持するのがずっと難しくなります。 –