tags:

views:

325

answers:

4

I am making an imaging application. I need a 16000 x 16000 pixel image. This is not impossible because in PhotoShop I can create this image for print. (56 x 56 inches, in 300dpi)

I am using this code:

Image WorkImage = new Bitmap(16000, 16000);

This generates an "Invalid Parameter" exception, but not when I do 9000 x 9000 Pixels.

MSDN doesn't say anything about the limits in the constructor.

I know that the data in the bitmap object is in memory, because if the array is too big it can throw an "Out Of Memory" exception, but this is not the case. I would prefer manage this data in a file, but I don't know how.

Thanks.

+4  A: 

Why not generate a bunch of smaller bitmaps? E.g. 16 bitmaps that are 4k x 4k pixels...?

Oh, and although probably not the cause of the exception you got, there are some funny quirks with large objects / the CLR large object heap. This is covered in some other SO topics that you may want to read just for fun since you're playing with large chunks of memory... E.g.: http://stackoverflow.com/questions/1037344/how-to-get-unused-memory-back-from-the-large-object-heap-loh-from-multiple-manage

KristoferA - Huagati.com
Yep, my thought exactly.
Charlie Salts
Yup, I didn't see your reply when I posted mine. I guess we hit 'add answer' at around the same time... :)
KristoferA - Huagati.com
+6  A: 

Photoshop does not allocate gigantic images in contiguous portions of memory as you are trying to do. There are some memory limitations I've encountered when creating very large images.

Consider subdividing your images. This has the benefit of better memory management. If you edit one of your subdivided images, you won't have to update the entire image.


As an aside, a 16000 x 16000 at 4 bytes per pixel is roughly a gigabyte! That's huge. Good luck!

Charlie Salts
+2  A: 

While I agree with Charlie that you're probably better off with several smaller bitmaps, I just ran the code below on my 32 bit Windows with 2 GB RAM, and it took a while to complete, but I received no errors.

var b = new Bitmap(16000, 16000);
Console.WriteLine("size is {0}x{1}", b.Width, b.Height);
Brian Rasmussen
Thanks Brian! I didn't see any immediate technical reason in the CLR why it would fail, and now I know. :)
280Z28
A: 

Really, dont mind where is the Bitmap Data. I only need in the output a file (TIFF) with the 16000 x 16000 pixels image. I think that i can create a class (How the bitmap class and the image class) but with the data in the file itself, where i can edit the image.

I am thinking to check the TIFF structure and create a class for create and edit those files partially buffered in memory. I dont want create a object that are more big than a few MB.

But i want to know if there is some class with BMP or TIFF File editing capability... really i dont know.

Thanks for your previous Answers. :)