Scale an Image in C# Preserving Aspect Ratio

If you need to change the size of an Image without changing the ratio of X to Y then this function should do what you want.

The input parameters maxWidth and maxHeight define the largest values that you want to get back out of the image after it has been scaled.

Results of Scaling an Image

Here is a test image that we loaded into the scale function.


And here it is after calling for a maxWidth of 5000 and a maxHeight of 200.


You can see that the maxHeight of 200 was obeyed and the image was scaled while maintaining a proper aspect ratio.

Other Image Processing Guides

You may want to check out some of our other Image Processing Guides in C#.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.