Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

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

Re: JPEG/GIF vergrößern oder verkleinern

  Alt 27. Mai 2006, 12: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;
$2B or not $2B
  Mit Zitat antworten Zitat