Chris

Chris

  • NA
  • 1
  • 0

Out of Memory Exception when resizing Bitmap

Apr 1 2009 4:08 PM
So, the function works great for smaller image, but as I try to increase the size of the resized Image, eventually I will run into an Out of Memory Exception.

The function I currently have is:

public static Bitmap ResizeImage(Bitmap srcImage, int width, int height)
        {
            Bitmap result = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage((Image)result))
                g.DrawImage(srcImage, new Rectangle(0, 0, width, height), new Rectangle(0, 0, srcImage.Width, srcImage.Height), GraphicsUnit.Pixel);
            return result;
        }

Any thoughts to improve/change the method to not get the OOM Exception?

Answers (2)