Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycaroafonso/7995346 to your computer and use it in GitHub Desktop.
Save ycaroafonso/7995346 to your computer and use it in GitHub Desktop.
public static System.Drawing.Image Redimensionar(System.Drawing.Image image, int NewWidthMax, int NewHeightMax)
{
float Fator = 0;
if (image.Width / WidthMaximo > image.Height / HeightMaximo)
Fator = (float)image.Width / WidthMaximo;
else
Fator = (float)image.Height / HeightMaximo;
int NewWidth = (int)((float)image.Width / Fator);
int NewHeight = (int)((float)image.Height / Fator);
Bitmap newImage = new Bitmap(NewWidth, NewHeight);
using (Graphics gr = Graphics.FromImage(newImage))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(image, new Rectangle(0, 0, NewWidth, NewHeight));
}
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment