Thema: Delphi Image resizer

Einzelnen Beitrag anzeigen

Douglas Quintaine
(Gast)

n/a Beiträge
 
#3

Re: Image resizer

  Alt 21. Dez 2008, 09:23
Delphi-Quellcode:
procedure CopyImagePart(const src: TGraphic; const dest: TBitmap; aWidth, aHeight: Integer);
var
  tempBMP: TBitmap;
begin
  tempBMP := TBitmap.Create;
  try
    tempBMP.Width := src.Width;
    tempBMP.Height := src.Height;
    tempBMP.Assign(src);
    dest.Width := aWidth;
    dest.Height := aHeight;
    BitBlt(dest.Canvas.Handle,0,0,aWidth,aHeight,tempBMP.Canvas.Handle,0,0,SRCCOPY);
  finally
    tempBMP.Free;
  end;
end;

procedure ReSizeJPGImage(url: String; x,y: Integer);
var
 aCopy: TBitmap;
 JPG: TJPEGImage;
begin
  JPG := TJPEGImage.Create;
   try
     aCopy := TBitmap.Create;
     try
       JPG.LoadFromFile(url);
       CopyImagePart(JPG,aCopy,x,y);
       aCopy.SaveToFile(url);
     finally
       aCopy.Free;
     end;
   finally
     JPG.Free;
   end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ReSizeJPGImage(edit1.Text, 260,30); // (url, x, y)
end;
  Mit Zitat antworten Zitat