Recent

Author Topic: how to resize an image mantaining aspect ratio.  (Read 3866 times)

dcelso

  • Full Member
  • ***
  • Posts: 158
how to resize an image mantaining aspect ratio.
« on: January 27, 2013, 12:50:22 pm »
  hello to all. I have program to load a image on a timage. The image can be any known format of timage can load.

I need put a preview of the image in a 50x50 container so i want resize it maintaining aspect ratio. The result will be a 50x? Image or ?x50 image.
 what is the better method to do it.?

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: how to resize an image mantaining aspect ratio.
« Reply #1 on: January 27, 2013, 01:50:23 pm »
Use math and logics. You get the relative size by Width/Height. For example 400x200 would give you 2, also that 200x200 image would result 1. So if x>1, then image is horizontally bigger. Same relation number can be used as a multiplier.
For example if you draw image horizontally, you can
image.width := 50;
image.height := 50 / x;

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: how to resize an image mantaining aspect ratio.
« Reply #2 on: January 27, 2013, 02:16:46 pm »
Yes. I know it. But what function and image container can i use in Lazarus? For example Tlazimginterfaz has methods to do it?

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: how to resize an image mantaining aspect ratio.
« Reply #3 on: January 27, 2013, 03:30:53 pm »
TPanel and TImage in it for example. TImage has Stretch property which you could use in this case.

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: how to resize an image mantaining aspect ratio.
« Reply #4 on: January 27, 2013, 04:04:14 pm »
 :o, thanx i will try it

 

TinyPortal © 2005-2018