Last active
August 29, 2015 14:23
-
-
Save abe238/4c2a5ed65cddba3d7a8b to your computer and use it in GitHub Desktop.
Scale Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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