Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient handling of super wide, but not so tall, bitmap?

Is there any way to create a more space/resource efficient bitmap? Currently I try to render a file, approx 800px high but around 720000px wide. It crashes my application, presumably because of the share memory-size of the bitmap.

Can I do this more efficiently, like creating it as an gif directly and not later when I save it?

I try to save a series of lines/rectangles from a real world reading, and I want it to be 1px per 1/100th of a second.

like image 961
Erik Karlsson Avatar asked Apr 12 '10 17:04

Erik Karlsson


2 Answers

You have to remember that any image you load into memory regardless if it's a GIF or JPEG or whatever on disk will be turned into a 32 bit bitmap which means four bytes per pixel.

This means that the image you're creating will be:

4 bytes * 800 pixels high * 720,000 pixels wide = 2,304,000,000 bytes

You're basically blowing your memory by trying to create an image that large.

For whatever you're trying to accomplish the answer is tiling and caching your image.

like image 70
Paul Sasik Avatar answered Nov 15 '22 06:11

Paul Sasik


Your image is about 2.3 gig, and the biggest .Net object you can have is 2 gig regardless if the machine is 32 or 64 bit.

You're going to have to break the bitmap up in chunks to handle an image that size.

like image 26
kemiller2002 Avatar answered Nov 15 '22 06:11

kemiller2002