Created
February 16, 2015 15:50
-
-
Save mdauphin/72cde0fe90f987906bdc to your computer and use it in GitHub Desktop.
Rescale with ratio conserve
This file contains hidden or 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
Size Rescale(Size original) | |
{ | |
// Figure out the ratio | |
double ratioX = (double)ThumbmailSize.Width / (double)original.Width; | |
double ratioY = (double)ThumbmailSize.Height / (double)original.Height; | |
// use whichever multiplier is smaller | |
double ratio = ratioX < ratioY ? ratioX : ratioY; | |
// now we can get the new height and width | |
int newWidth = Convert.ToInt32(original.Width * ratio); | |
int newHeight = Convert.ToInt32(original.Height * ratio); | |
return new Size(newWidth, newHeight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment