Processing on large raster images (up to 3 GB)

I am working on some university project and am stuck in a memory problem. I am downloading a bitmap that takes about 1.5 GB on the hard drive with the code below:

Bitmap bmp = new Bitmap(pathToFile); 

The problem is that the newly created Bitmap object uses about 3.5 GB of RAM, which I cannot understand (this is really a BIG shell: E). I need to get an array of pixels, and using the Bitmap class is really useful (later I use the LockBits () method and process the byte array for each byte), but in this case it is a complete blocker. So here is my question:

Is there an easy way to extract an array of pixels without providing extra 2gb?

I use C # only to retrieve the required array, which is later processed in C ++ - maybe I can extract all the necessary data in C ++ (but the conversion problem appears here - I focus on 24bgr format)?

PS: I need to save the entire bitmap in memory, so dividing it into parts is not a solution.

PS2: just to find out some problems: I know the difference between a file extension and a file format. The downloaded file is an uncompressed bitmap of 3 bytes per pixel ~ 1.42GB in size (16k x 32k pixels), so why is the Bitmap object more than twice as large? Any problems with unpacking and conversion to another format are not performed.

+6
source share
3 answers

Consider using memory files to access your HUGE data :). An example that focuses on what you need can be found here: http://visualstudiomagazine.com/articles/2010/06/23/memory-mapped-files.aspx This is in managed code, but you can also use it from the equivalent code.

Let me know if you need more information.

+1
source
0
source

You can stop memory caching.

Instead

Bitmap bmp = new Bitmap(pathToFile);

Using

var bmp = (Bitmap)Image.FromStream(sourceFileStream, false, false);

see https://stackoverflow.com>

0
source

All Articles