Skip to content

Instantly share code, notes, and snippets.

@abe238

abe238/ScaleImage

Last active Aug 29, 2015
Embed
What would you like to do?
Scale Image
public static Image ScaleImage(Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newImage = new Bitmap(newWidth, maxHeight);//
Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, maxHeight);//
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment