Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.171 Beiträge
 
Delphi 12 Athens
 
#3

Re: JPEG/GIF vergrößern oder verkleinern

  Alt 27. Mai 2006, 11:27
Zitat von turboPASCAL:
Ja.

Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
  Image.Picture.Graphic.Width := newWidth;
  Image.Picture.Graphic.Height := newHeight;
end;
nein, denn das stimmt nur für's Verkleinern

Das wäre dann nur für's Vergrößern:
Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  Image.Picture.Graphic.Width := newWidth;
  Image.Picture.Graphic.Height := newHeight;
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
end;
Es muß im Bild halt immer das größte Maß eingestllt werden:
Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  If Image.Picture.Graphic.Width < newWidth Then
    Image.Picture.Graphic.Width := newWidth;
  If Image.Picture.Graphic.Height < newHeight Then
    Image.Picture.Graphic.Height := newHeight;
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
  If Image.Picture.Graphic.Width > newWidth Then
    Image.Picture.Graphic.Width := newWidth;
  If Image.Picture.Graphic.Height > newHeight Then
    Image.Picture.Graphic.Height := newHeight;
end;
Das geht och, da .Width/.Height intern och nochma abfragen (sollten) ob wirklich geändert wird:
Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  If Image.Picture.Graphic.Width < newWidth Then
    Image.Picture.Graphic.Width := newWidth;
  If Image.Picture.Graphic.Height < newHeight Then
    Image.Picture.Graphic.Height := newHeight;
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
  Image.Picture.Graphic.Width := newWidth;
  Image.Picture.Graphic.Height := newHeight;
end;
Oder halt so:
Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  Image.Picture.Graphic.Width := Max(Image.Picture.Graphic.Width, newWidth);
  Image.Picture.Graphic.Height := Max(Image.Picture.Graphic.Height, newHeight);
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
  Image.Picture.Graphic.Width := newWidth;
  Image.Picture.Graphic.Height := newHeight;
end;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat