Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutofMemoryException - Loading Extremely Large Images

I'm trying to load an extremely large image (14473x25684), but I'm hitting into a memory limitation.

Here's a simple program to demonstrate the problem:

static void Main(string[] args)
{
    string largeimage = @"C:\Temp\test_image.jpg"; // 14473x25684

    Image i = Bitmap.FromFile(largeimage); // OutofMemoryException was unhandled
}

Now I understand that the issue isn't relevant to how much physical memory I have, but rather is an addressing limitation. Is there anything I can do to get around this limitation?

The image is indeed valid and it opens fine in Photoshop (VM Size: 916MB) and ACDSee. Also don't bother to Google the dimensions as the dimensions listed aren't exact. :)

Thank you for your time.

like image 526
Generic Comrade Avatar asked Aug 24 '10 04:08

Generic Comrade


1 Answers

The Bitmap class will require around 1.5GB of memory to hold that instance. The .NET memory allocator normally chokes around the 1GB mark.

like image 192
leppie Avatar answered Nov 04 '22 11:11

leppie