Recent

Author Topic: Resize image OSX  (Read 1320 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Resize image OSX
« on: May 05, 2018, 06:44:27 pm »
I'm trying to figure out how to save a resized image (I'm on macOS Sierra 10.12.6)

I've tried using the example from here: http://delphidabbler.com/tips/99 but the saved image isn't resized, just cropped.

Using TImage I can resize it on the form, but the saved image is the original size.

I did see references to StretchBlt but I can't find enough information to figure out how to apply it.

Anyone got a working example for OSX of loading a file, resizing, and saving a scaled version?

laguna

  • Sr. Member
  • ****
  • Posts: 274
Re: Resize image OSX
« Reply #1 on: May 09, 2018, 09:00:50 am »
I use this:



Code: Pascal  [Select]
  1.  
  2. ....    // New size + 20%
  3.     NewWith := mWidth;
  4.     NewWith := NewWith - (NewWith * 20 / 100);
  5.  
  6.     AspectRatio := imgOrign.Picture.Height / imgOrign.Picture.Width;
  7.     iMain.Visible := False;
  8.     iMain.Picture.Assign(imgOrign.Picture);
  9.     mWidth := trunc(NewWith);
  10.     mHeight := round(AspectRatio * mWidth);
  11.  
  12.     if ResizeBmp(iMain.Picture.Bitmap, mWidth, mHeight) = True then
  13.     begin
  14.     end;
  15. .....
  16.  
  17. function TMainForm.ResizeBmp(bitmp: TBitmap; wid, hei: integer): boolean;
  18. var
  19.   TmpBmp: TBitmap;
  20.   ARect: TRect;
  21. begin
  22.   Result := False;
  23.   try
  24.     TmpBmp := TBitmap.Create;
  25.     try
  26.       TmpBmp.Width := wid;
  27.       TmpBmp.Height := hei;
  28.       ARect := Rect(0, 0, wid, hei);
  29.       TmpBmp.Canvas.StretchDraw(ARect, Bitmp);
  30.       bitmp.Assign(TmpBmp);
  31.     finally
  32.       TmpBmp.Free;
  33.     end;
  34.     Result := True;
  35.   except
  36.     Result := False;
  37.   end;
  38. end;
  39.