Recent

Author Topic: How to resize proportionally an image in canvas form  (Read 6107 times)

Christian_uy

  • Newbie
  • Posts: 2
How to resize proportionally an image in canvas form
« on: June 23, 2013, 06:54:44 pm »
Hello evrebody
I have this code take from the tutorial nº 2

procedure TForm1.FormPaint(Sender: TObject);
var stretched: TBGRABitmap;
begin
    stretched := image.Resample(ClientWidth, ClientHeight) as TBGRABitmap;
    stretched.Draw(Canvas,0,0,True);
    stretched.Free;

    //image.Draw(Canvas,0,0,True);
end;

but loose proportions.
I don't care if image does not cover the entire form in both width and length directions.
¿ Anyone know if there is a property similar to the property Stretch in the TImage class or a method that can do that ?
Thanks Christian.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: How to resize proportionally an image in canvas form
« Reply #1 on: June 23, 2013, 08:13:22 pm »
See:
http://forum.lazarus.freepascal.org/index.php/topic,20709.msg120369.html#msg120369
Regards
p.s. set: original_with * rescaleVal, original_height * rescaleVal (e.g rescaleValue = 1.2 //20%)

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: How to resize proportionally an image in canvas form
« Reply #2 on: June 23, 2013, 08:28:27 pm »
You can find in examples, this procedure(very useful):
------------
procedure TForm1.RescaleImage(newScale: Double);
var
  OrgWidth, OrgHeight: integer;
  Rect: TRect;
begin
  OrgWidth := Image1.Picture.Bitmap.Width;
  OrgHeight := Image1.Picture.Bitmap.Height;
  FImageScale := FImageScale * NewScale; //FImageScale-> private 1.0 on start(original)
  Rect := Image1.BoundsRect;
  Rect.Right := Rect.Left + Round(OrgWidth * FImageScale);
  Rect.Bottom := Rect.Top + Round(OrgHeight * FImageScale);
  Image1.Align := AlNone;
  Image1.BoundsRect := Rect;
  Image1.Stretch:= true;   //strech
end;

Christian_uy

  • Newbie
  • Posts: 2
Re: How to resize proportionally an image in canvas form
« Reply #3 on: June 25, 2013, 05:12:24 am »
Thanks for the fast reply Exdatis!. I'll be trying this as soon as possible.

 

TinyPortal © 2005-2018