Skip to content

Instantly share code, notes, and snippets.

@briandonahue
Created October 13, 2011 20:50
Show Gist options
  • Save briandonahue/1285485 to your computer and use it in GitHub Desktop.
Save briandonahue/1285485 to your computer and use it in GitHub Desktop.
Image Resizing
Bitmap targetBitmap = new Bitmap(sourceImage, imageSize);
Bitmap canvas = new Bitmap(imageSize.Width, imageSize.Height);
// Set appropriate resolution
targetBitmap.SetResolution(72F, 72F);
Graphics g = Graphics.FromImage(canvas);
// Makes resized image have a higher quality
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// Draw image to new size and resolution
g.DrawImage(targetBitmap, 0, 0, imageSize.Width, imageSize.Height);
targetBitmap.Save(destinationImagePath, ImageFormat.Jpeg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment