Here’s the problem. I have a picture that will have a different Height every time according to the picture that’s loaded.
I’d like to scale that picture so it fits inside of the document which has 800 pixels height. So if the image has 2560px in height, I need to find out the PERCENTAGE needed to bring that pixel height down to 750 so it fits snuggly on the page.
I’m stuck trying to find the formula for this simple enough problem.
Here’s my code:
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(
image, System.Drawing.Imaging.ImageFormat.Jpeg);
if (pic.Height > pic.Width)
{
//Maximum height is 800 pixels.
pic.Height formula goes here....
}
else
{
//Maximum width is 600 pixels.
pic.Width formula goes here....
}
Some number
pis such thatp * 2560 = 750. Therefore,p = 750 / 2560 = 0.29296875.Of course, make sure that you do floating-point division.