Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing on large bitmaps (up to 3GB)

I'm working on some university project and got stuck with memory issue. I load a bitmap which takes about 1,5GB on HDD with code below:

Bitmap bmp = new Bitmap(pathToFile); 

The issue is that the newly created Bitmap object uses about 3,5GB of RAM which is something I can't understand (that's really BIG wrapper :E). I need to get to the pixel array, and the use of Bitmap class is really helpful (I use LockBits() method later, and process the array byte per byte) but in this case it's total blocker. So here is my question:

Is there any easy way to extract the pixel array without lending additional 2gb?

I'm using c# just to extract the needed array, which is later processed in c++ - maybe I can extract all needed data in c++ (but conversion issue appears here - I'm concentrating on 24bgr format)?

PS: I need to keep the whole bitmap in memory so splitting it into parts is no solution.

PS2: Just to clarify some issues: I know the difference between file extension and file format. The loaded file is uncompressed bitmap 3 bytes per pixel of size ~1.42GB (16k x 32k pixels), so why Bitmap object is more than two times bigger? Any decompressing issues and converting into other format aren't taking place.

like image 979
Rafal Chmiel Avatar asked Jun 16 '12 17:06

Rafal Chmiel


People also ask

Does bitmap have a large file size?

BMP stands for bitmap, a raster-based file type designed in the early days of computer graphics to display images independently from devices. Because BMP files are information-rich, they tend to have large file sizes.

Why are bitmap files so big?

BMP files are sometimes known as “true images” because they render each individual pixel within the file. They don't compress automatically. This makes them large — a collection of BMP files will rapidly consume lots of memory and space.

What happens when you increase the size of a bitmap image?

When zooming in or enlarging a bitmap image, the pixels are stretched and made into larger blocks. This is why bitmap images appear as poor quality when enlarged too much. Each colour of an image is stored as a binary number.

How do you handle bitmaps in Android?

For most cases, we recommend that you use the Glide library to fetch, decode, and display bitmaps in your app. Glide abstracts out most of the complexity in handling these and other tasks related to working with bitmaps and other images on Android.


1 Answers

Consider using Memory Mapped Files to access your HUGE data :). An example focused on what you need can be found here: http://visualstudiomagazine.com/articles/2010/06/23/memory-mapped-files.aspx It's in managed code but you might as well use it from equivalent native code.

Let me know if you need more details.

like image 170
Marcel N. Avatar answered Oct 01 '22 07:10

Marcel N.