Created
August 20, 2010 11:07
-
-
Save chakrit/540086 to your computer and use it in GitHub Desktop.
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
private Size shrinkSize(Size origSize) | |
{ | |
const int maxWidth = 900; | |
const int maxHeight = 700; | |
const double flipRatio = (double)maxWidth / maxHeight; | |
if (origSize.Width < maxWidth && | |
origSize.Height < maxHeight) | |
return origSize; | |
// determine wether its better to shrink by height or by width | |
var ratio = (double)origSize.Width / origSize.Height; | |
if (ratio < flipRatio) | |
return new Size( | |
(int)(origSize.Width * ((double)maxHeight / origSize.Height)), | |
maxHeight); | |
else | |
return new Size( | |
maxWidth, | |
(int)(origSize.Height * ((double)maxWidth / origSize.Width))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment