Proportionately Resizing A Bitmap in C#
Resizing a bitmap and keeping the sides proportions intact - in other words keeping the same aspect ratio, we need to specify a maximum width and maximum height.
The first thing we do is get the longest and shortest dimensions and divide the one by the other. We then have the ratio of the two sides which we will use further on in the calculations.
Then, finding the new width and height, we set the new width to the maximum width, and the new height to the maximum height divided by the ratio of the sides. If however, the height was the largest side, we then set the new height to the maximum height, and the width to maximum width divided by the ratio of the sides.
Once we have done this, we can then create a new Bitmap from the old Bitmap, using the new width and height we have calculated and then return the Bitmap as the last thing we do.
Originally posted on my old blog, Smoky Cogs, on 15 Nov 2009