Skip to content

Instantly share code, notes, and snippets.

@abe238
Last active August 29, 2015 14:23
Show Gist options
  • Save abe238/4c2a5ed65cddba3d7a8b to your computer and use it in GitHub Desktop.
Save abe238/4c2a5ed65cddba3d7a8b to your computer and use it in GitHub Desktop.
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