2
Answers

Out of Memory Exception when resizing Bitmap

Chris

Chris

14y
19.3k
1
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)