开发者

OutofMemoryException - Loading Extremely Large Images

开发者 https://www.devze.com 2023-01-13 07:16 出处:网络
I\'m trying to load an extremely large image (14473x25684), but I\'m hitting into a memory limitation.

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 th开发者_如何学编程at 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.


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


OS can not allocate contiguous amount of memory. All you can do about that is use of MemoryFailPoint and catch InsufficientMemoryException. But this only save you from app crashing.
As for me, to open such a big file you should use binary reader and draw a file via System.Drawing.

here is good question and answers When is it OK to catch an OutOfMemoryException and how to handle it?

0

精彩评论

暂无评论...
验证码 换一张
取 消