Reputation: 372
My website integrates a plugin that allows the user to upload pictures to it.
It works fine with most pictures but will raise an OutOfMemoryException on any pictures that it feels are too large.
Here is the code that crashes :
Image img = Image.FromFile(path);
Image test = (Image)(new Bitmap(img, new Size(img.Width, img.Height))); //OutOfMemoryException
It really is all about resolution as :
Image 1 => 3.79Mb, 4200x2850 does not crash
Image 2 => 1.82Mb, 7360x4912 causes a crash
Where did I go wrong ?
Upvotes: 1
Views: 913
Reputation: 372
This error was occurring on an MVC web application. It was caused by running a 32-bit IISEXPRESS server which forced the memory allocation of the bitmap to be contiguous instead of using any available chunks.
The solution was to force IISEXPRESS to run in 64-bit by going into the following Visual Studio settings :
TOOLS>OPTIONS>Projects and Solutions>WEB PROJECT and check the 64-bit IISEXPRESS box
Upvotes: 3