Skip to content

Instantly share code, notes, and snippets.

@mdauphin
Created February 16, 2015 15:50
Show Gist options
  • Save mdauphin/72cde0fe90f987906bdc to your computer and use it in GitHub Desktop.
Save mdauphin/72cde0fe90f987906bdc to your computer and use it in GitHub Desktop.
Rescale with ratio conserve
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