Verwende
ImgList.PngImages.BeginUpdate und
ImgList.PngImages.EndUpdate, das dürfte den Vorgang erheblich beschleunigen.
Edit: Beispiel ohne Fehlerbehandlung
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const
TimeFormat = 'nn:ss:zzz';
var I: Integer;
StartTime, EndTime: TDateTime;
TempFileName: String;
TempImg: TPNGObject;
TempBMP: TBitmap;
RandomRect: TRect;
C: TCanvas;
begin
TempBMP := TBitmap.Create;
TempBMP.Width := 32;
TempBMP.Height := 32;
C := TempBMP.Canvas;
C.Pen.Style := psSolid;
C.Brush.Style := bsSolid;
for I := 0 to 100 do begin
C.Pen.Color := Random(clWhite);
C.Brush.Color := Random(clWhite);
RandomRect := Rect(Random(TempBMP.Width), Random(TempBMP.Height),
Random(TempBMP.Width), Random(TempBMP.Height));
C.FillRect(RandomRect);
end;
TempFileName := IncludeTrailingPathDelimiter(GetEnvironmentVariable('Temp')) +
'PngImageListTest.png';
TempImg := TPNGObject.Create;
TempImg.Assign(TempBMP);
TempImg.SaveToFile(TempFileName);
TempBMP.Free;
TempImg.Free;
StartTime := Now;
ImgList.PngImages.BeginUpdate;
for I := 0 to 300 do begin
ImgList.PngImages.Add(False).PngImage.LoadFromFile(TempFileName);
end;
ImgList.PngImages.EndUpdate;
EndTime := Now;
Label1.Caption := 'Total: ' + FormatDateTime(TimeFormat, EndTime - StartTime);
end;
Dani H.
At Least I Can Say I Tried