C# "Parameter is not valid." creating new bitmap

Solution 1:

Keep in mind, that is a LOT of memory you are trying to allocate with that Bitmap.

Refer to http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/37684999-62c7-4c41-8167-745a2b486583/

.NET is likely refusing to create an image that uses up that much contiguous memory all at once.

Slightly harder to read, but this reference helps as well:

http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.drawing/2005-06/msg00176.html

Each image in the system has the amount of memory defined by this formula:

bit-depth * width * height / 8

This means that an image 40800 pixels by 4050 will require over 660 megabytes of memory.

Solution 2:

19000 pixels square, at 32bpp, would require 11552000000 bits (1.37 GB) to store the raster in memory. That's just the raw pixel data; any additional overhead inherent in the System.Drawing.Bitmap would add to that. Going up to 20k pixels square at the same color depth would require 1.5GB just for the raw pixel memory. In a single object, you are using 3/4 of the space reserved for the entire application in a 32-bit environment. A 64-bit environment has looser limits (usually), but you're still using 3/4 of the max size of a single object.

Why do you need such a colossal image size? Viewed at 1280x1024 res on a computer monitor, an image 19000 pixels on a side would be 14 screens wide by 18 screens tall. I can only imagine you're doing high-quality print graphics, in which case a 720dpi image would be a 26" square poster.

Solution 3:

I suspect you're hitting memory cap issues. However, there are many reasons a bitmap constructor can fail. The main ones are listed in this Knowledge Base article talking about GDI+ limits in CreateBitmap. System.Drawing.Bitmap, internally, uses the GDI native API when the bitmap is constructed.

That being said, a bitmap of that size is well over a GB of RAM, and it's likely that you're either hitting the scan line size limitation (64KB) or running out of memory.