Resize an Image in C#

tech — tags: , — rohand @ June 3, 2010 11:46 AM

This function will let you resize an image in C#.

public static Bitmap Resize(Bitmap original,
                        int width, int height)
{
  Bitmap bitmap = new Bitmap(width, height);

  using (Graphics gfx = Graphics.FromImage(bitmap))
  {
    gfx.InterpolationMode
            = Drawing2D.InterpolationMode.HighQualityBicubic;
    gfx.SmoothingMode
            = Drawing2D.SmoothingMode.HighQuality;
    gfx.PixelOffsetMode
            = Drawing2D.PixelOffsetMode.HighQuality;
    gfx.CompositingQuality
            = Drawing2D.CompositingQuality.HighQuality;

    gfx.DrawImage(original, 0, 0, width, height);

    return bitmap;
  }
}
©2012 appytizers. All rights reserved.