Rezise Image using Aspect Ratio

B

Brian K. Williams

If I have an image 400 width by 500 height.
I can figure out my aspect ratio like this: float
Ratio=((float)nOrigWidth)/((float)nOrigHeight);
How can I use this value if I want to change the width to 200?


Thanks in advance.
Brian K. Williams
 
N

Nicholas Paldino [.NET/C# MVP]

Brian,

It's simple. Your ratio is expressed in terms of width to height:

ratio = originalWidth / originalHeight

If you want to get a new width or height, your equation becomes:

originalWidth newWidth
-------------- = ---------
originalHeight newHeight

But the left hand side is equal to the ratio you already computed, so it
becomes:

newWidth
ratio = ---------
newHeight

Substituting the values you have, you get:

newHeight = newWidth / ratio

Subsequently, if you have the new height, and want the new width, the
formula is:

newWidth = newHeight * ratio

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top