Drawing large bitmaps

P

Pete Davis

I'm having trouble dealing with bitmaps larger than about 10,000 pixels in
either direction.

I've tried using DrawImage and DrawImageUnscaled, but both give me out of
memory errors.

In my case, I'm simply trying to draw a portion of the bitmap. The portion
is slightly under the 1600x1200 size of my screen.

When trying to do it, I get an Out of Memory exception.

Searching Google returned this issue as common with large, but what I
haven't been able to find is a workaround.

Anyone have any ideas? Am I going to have to write unamanaged code to do
this?

Pete
 
W

Willy Denoyette [MVP]

Pete Davis said:
I'm having trouble dealing with bitmaps larger than about 10,000 pixels in
either direction.

I've tried using DrawImage and DrawImageUnscaled, but both give me out of
memory errors.

In my case, I'm simply trying to draw a portion of the bitmap. The portion
is slightly under the 1600x1200 size of my screen.

When trying to do it, I get an Out of Memory exception.

Searching Google returned this issue as common with large, but what I
haven't been able to find is a workaround.

Anyone have any ideas? Am I going to have to write unamanaged code to do
this?

Pete

Any idea how large your bitmap of 10000 * 10000 is in Mb?
The fact that you only draw a portion of it doesn't matter, the whole bitmap
file has to be mapped in your Virtual Address space.

Willy.
 
P

Pete Davis

Well, the process is getting up to about 500MB at the time of the exception.
Well within the 2 1/2 gb of my system. 10,000x10,000x32 is only about 400MB.
With virtual memory, I could do about 8-10 times that.

I don't think the computer is literally running out of memory.

I've loaded larger in Adobe Photoshop and it doesn't crash.


Pete
 
W

Willy Denoyette [MVP]

Not at all, each process in Windows (32 bit) has a maximum of 2GB available
as Virtual Address Space (VAS), this 2GB is used to load code pages as well
as Data pages, your Bitmap is loaded by GDI+ (used by System.Drawing) from a
Filestream into a native heap buffer and copied to the Image buffer, also in
the native heap, that means you need aprox. two times (the file is somewhat
smaller ) the size of the raw image, that is two contiguous blocks of 400Mb
of memory. The problem however is GDI+ (gdiplus.dll) which is loaded
somewhere at address 0x4ec50000[1] in VAS, while most other DLL's are loaded
at top of memory and your code modules at the bottom together with the GC
heap. While in general you may have a total of 1.9 GB VAS available, there
is no guarantee there is 800 Mb available in one large chunk, or two chunks
of > 400Mb, especial if there are other modules or data-structures loaded or
when there are many objects allocated from the GC heap.
Note also that you can't compare Photoshop (not using GDI+) and .NET which
is using GDI+.

Willy.

[1] this custs the initial heap into two portions one of ~1.2 Gb and another
of ~360Mb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top