Advertisement
adnan360

Resize a JPG image and save it

Oct 23rd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.77 KB | None | 0 0
  1. // http://lazplanet.blogspot.com
  2. // Adnan Shameem
  3. // Imagefile = The jpg file that you want to resize
  4. // W, H = Image destination width and height
  5. // DestFile = Destination file where the resized image should be saved
  6. function TForm1.ResizeAndSave(ImageFile: String; W: Integer; H: Integer;
  7.          DestFile: String):Boolean;
  8. var
  9.   bmp: TBitmap;
  10.   jpg: TJPEGImage;
  11. begin
  12.   try
  13.     try
  14.       jpg:=TJPEGImage.Create;
  15.       bmp:=TBitmap.Create;
  16.  
  17.       jpg.LoadFromFile(ImageFile);
  18.       bmp.Width:=w;
  19.       bmp.Height:=h;
  20.       bmp.Canvas.StretchDraw(Rect(0,0,w,h), jpg);
  21.       jpg.Assign(bmp);
  22.       jpg.SaveToFile(DestFile);
  23.  
  24.       Result:=true;
  25.  
  26.     except
  27.       Result:=False;
  28.  
  29.     end;
  30.  
  31.   finally
  32.     FreeAndNil(bmp);
  33.     FreeAndNil(jpg);
  34.   end;
  35. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement