Created
December 16, 2013 22:10
-
-
Save ycaroafonso/7995346 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
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