![]() |
Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateien)
Hi,
ich schreibe ein Programm, das Thumbnails erstellt, dazu benutze ich 2 Arrays of TPicture. Ich lade die Bilder mit LoadFromFile, ändere die Größe mit Stretchdraw und will dann wieder mit SaveToFile speichern. Aber irgendwie klappts nich so ganz. Es kommt zwar kein Fehler, aber ich hab nachher nur 0 KB Dateien im Zielordner... Hier mal der Code:
Delphi-Quellcode:
(Die Variablen:)
for i := 0 to count-1 do
begin srcpics[i].SaveToFile(dest + '\img' + inttostr(i) + '.jpg'); h := srcpics[i].Height; w := srcpics[i].Width; if h < w then begin p := h / w; r.Left := 1; r.Top := 1; r.Right := twidth; r.Bottom := round(p * twidth); tpics[i].Bitmap.Canvas.StretchDraw(r,srcpics[i].Graphic); tpics[i].SaveToFile(dest + '\t_img' + inttostr(i) + '.jpg'); end; if h >= w then begin p := w / h; r.Left := 1; r.Top := 1; r.Right := theight; r.Bottom := round(p * theight); tpics[i].Bitmap.Canvas.StretchDraw(r,srcpics[i].Graphic); tpics[i].SaveToFile(dest + '\t_img' + inttostr(i) + '.jpg'); end; end;
Delphi-Quellcode:
Global:
var Form1: TForm1; src, dest: string; twidth, theight, rows, cols, count: integer; comment: boolean; srcpics, tpics: array of TPicture; Lokal: var i, h, w: integer; var p, q: real; var r: TRect; |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Hallo,
Schau mal in Zeile 3, müßte da nicht LoadFromFile stehen und nicht SaveToFile. Gruß Reinhold |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Wieso?
Das ist schon richtig so. Das LoadFromFile ist noch mal vorher.
Delphi-Quellcode:
//EDIT: Übrigens, das speichern des Orginals im Zielordner funktioniert...
i := 0;
if SysUtils.FindFirst(Folder + '\*.jpg', faAnyFile, Rec) = 0 then try repeat inc(i); setlength(srcpics,i); srcpics[i-1] := TPicture.Create; srcpics[i-1].LoadFromFile(Folder + '\' + Rec.Name); until SysUtils.FindNext(Rec) <> 0; finally SysUtils.FindClose(Rec); end; |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Hallo,
vieleicht hilft Dir dieser Code, zur Ermittlung der neuen Größe.
Delphi-Quellcode:
Gruß Reinhold
function DestRect(DestWidth, DestHeight, SourceWidth, SourceHeight: Integer;
Center: Boolean): TRect; var cw, ch, w, h: Integer; xyaspect: Double; begin cw := DestWidth; ch := DestHeight; w := SourceWidth; h := SourceHeight; xyaspect := w / h; if w > h then begin w := cw; h := Trunc(cw / xyaspect); if h > ch then begin h := ch; w := Trunc(cw * xyaspect); end end else begin h := ch; w := Trunc(ch * xyaspect); if w > cw then begin w := cw; h := Trunc(ch / xyaspect); end end; with Result do begin Left := 0; Top := 0; Right := w; Bottom := h; end; if Center then OffsetRect(Result, (cw - w) div 2, (ch - h) div 2); end; |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Die Größe des Rechtecks ist ja korrekt, das habe ich schon überprüft.
|
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Hat den keiner ne Idee, woran es liegen kann???
|
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
normalerweise muss man das rect createn. oder ?
|
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Hallo,
du solltest vor dem Zeichnen eines Bilds die Größe des Zielbilds setzen:
Delphi-Quellcode:
Gruß Hawkeye
tpics[i].Bitmap.Width := ...;
tpics[i].Bitmap.Height := ...; |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Zitat:
²Chris: Auf den ersten Blick sehe ich den Fehler auch nicht... Gruß Stephan :dance: |
Re: Problem mit Stretchdraw/SaveToFile (Erstellt 0 KB Dateie
Zitat:
Das wars, jetzt klappts ;) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:58 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz