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

风格不统一 提交于 2019-12-23 11:55:55

问题


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.


回答1:


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.




回答2:


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.




回答3:


You're going to have to either:

  • Force x64 environment and get a stack load of RAM.

  • Change your architecture

Your image is going to be a little over 2 GB.




回答4:


Can i do it more efficient, like creating it as an gif directly and not later when i save it?

You can compress the image as you write it. It won't be in (uncompressed/unencoded) "bitmap" format anymore. Examples of compression algorithm include "run-length encoding" and "huffman".

Also, use the least possible color-depth: preferaby black-and-white, i.e. 1-bit-per-pixel.

Also perhaps save it in several, smaller, discontinuous memory chunks: instead of a single huge memory chunk (so huge that it can't even be allocated in the first place).




回答5:


If you create it as 720000px high and 800px wide as a bmp and rotate it when actually displaying it(*), you can stream the data directly to file in bitmap form. Maybe use RLE instead of raw bitmap; streaming in this manner should still be possible in that case.

(*)Displaying it is left as an exercise to the reader. You'll need tiling or something.



来源:https://stackoverflow.com/questions/2624187/efficient-handling-of-super-wide-but-not-so-tall-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!