Einzelnen Beitrag anzeigen

striderx

Registriert seit: 11. Feb 2007
Ort: Bergisch Gladbach
207 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Hilfe zu IThumbnailProvider

  Alt 6. Nov 2022, 20:49
Ich mache das (m. E. wesentlich einfacher) mit GDI+:

Delphi-Quellcode:
function GDIPMakeThumbnail(sSourceFile, sTargetFile: String;
                           AWidth, AHeight: Word): Boolean;

var
  BM: tBitmap;
  GR: tGPGraphics;
  GDPImage: TGPImage;
  GDPThumbnail: TGPImage;
  H: Single;
  R1: Single;
  R2: Single;
  W: Single;

begin
  Result := False;
  {............................................................................}
  if not tFile.Exists(sSourceFile) then Exit;
  {............................................................................}
  if (sTargetFile = '') or (sTargetFile = sSourceFile) then Exit;
  {............................................................................}
  if (AWidth < 10) or (AHeight < 10) then Exit;
  {............................................................................}
  BM := tBitmap.Create;
  BM.Width := AWidth;
  BM.Height := AHeight;
  GR := tGPGraphics.Create(BM.Canvas.Handle);
  GDPImage := TGPImage.Create(sSourceFile);
  {............................................................................}
  R1 := AWidth / AHeight;
  H := GDPImage.GetHeight;
  W := GDPImage.GetWidth;
  if (H = 0) or (W = 0) then Exit;
  {............................................................................}
  R2 := W / H;
  if R1 > R2 then begin
     W := AHeight * R2;
     H := AHeight;
  end
  else begin
     W := AWidth;
     H := AWidth / R2;
  end;
  {............................................................................}
  GDPThumbnail := GDPImage.GetThumbnailImage(Round(W), Round(H), nil, nil);
  GR.DrawImage(GDPThumbnail, MakeRect((AWidth - W) / 2, (AHeight - H) / 2, W, H));
  try
    BM.SaveToFile(sTargetFile);
    Result := True
  except
    ShowMsg('Fehler beim Speichern der Thumbnail-Datei', ' Fehler', mb_OK,
            mb_IconError);
  end;
  {............................................................................}
  GR.Free;
  GDPImage.Free;
  GDPThumbnail.Free;
  BM.Free;
end;

Geändert von striderx ( 6. Nov 2022 um 21:21 Uhr)
  Mit Zitat antworten Zitat