Skip to content

Instantly share code, notes, and snippets.

@xanathar
Created September 16, 2014 09:53
Show Gist options
  • Save xanathar/6954d46af5097218a7fe to your computer and use it in GitHub Desktop.
Save xanathar/6954d46af5097218a7fe to your computer and use it in GitHub Desktop.
Image resize w/System.Drawing
// Taken from http://social.msdn.microsoft.com/Forums/vstudio/en-US/a43fe625-a5cd-4438-895f-3ddeec6eb866/image-resizing-using-c?forum=csharpgeneral
public static System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height)
{
//a holder for the result
Bitmap result = new Bitmap(width, height);
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
//set the resize quality modes to high quality
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//draw the image into the target bitmap
graphics.DrawImage(image, 0, 0, result.Width, result.Height);
}
//return the resulting bitmap
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment