Hi Guys!
Just a quick question. As the title reads, I am trying to fit an image to the screen of an Android device and maintain its aspect ratio so as not to distort the image size ratio. I have searched the dictionary and cant seem to find a way to achieve this. If someone could point me in a direction for me to find the information I need (in the dictionary), that would be great!
Many Thanks,
Googie.
Example:
How To Fit An Image To The Screen While Maintaining Aspect Ratio.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: How To Fit An Image To The Screen While Maintaining Aspect Ratio.
Hi,
Here is a post about resize image
viewtopic.php?f=8&t=12653&p=60167&hilit=pourcrop#p60167
Best regards
Jean-Marc
Here is a post about resize image
viewtopic.php?f=8&t=12653&p=60167&hilit=pourcrop#p60167
Best regards
Jean-Marc
https://alternatic.ch
Re: How To Fit An Image To The Screen While Maintaining Aspect Ratio.
I check the image dimensions to see if I need to resize by height or width (in your example image, you'd want to fit the image by its width.) Then I call one of the following handlers. The params are:
This positions the resized image at the top left of the card, which in my case is where I wanted it. If that isn't where you want it, you can move the resized image to its original top left, or to the card loc, or wherever you need it. Or you could adjust the handlers to add the new widths and heights to the original image rect.
It wouldn't be difficult to pass another parameter specifying whether to resize by height or width, and then this could be a single handler instead of two.
- pObj = control reference; name or ID or long ID, etc.
- pOrigImgHeight = the formattedHeight of the image
- pOrigImgWidth = the formattedWidth of the image
Code: Select all
on resizeToHeight pObj,pOrigImgHeight,pOrigImgWidth
put (the height of this cd)/pOrigImgHeight into tRatio
set the rect of pObj to 0,0,(pOrigImgWidth * tRatio),(pOrigImgHeight * tRatio)
end resizeToHeight
on resizeToWidth pObj,pOrigImgHeight,pOrigImgWidth
put (the width of this cd)/pOrigImgWidth into tRatio
set the rect of pObj to 0,0,(pOrigImgWidth * tRatio),(pOrigImgHeight * tRatio)
end resizeToWidth
It wouldn't be difficult to pass another parameter specifying whether to resize by height or width, and then this could be a single handler instead of two.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How To Fit An Image To The Screen While Maintaining Aspect Ratio.
Thank you so much Jacque!!! Exactly what I needed!