Arko Jarko
Arko Jarko

Reputation: 39

How to write big image directly into bmp file (without creating bitmap object in memory) in c#?

Hello good smart programmers,

I need to merge small images into one big image which will have dimension about 7600 x 7600 px. When I create it in memory it takes too much memory I can't afford that.

I think good way to do this is make buffer (for every small picture which i want to put in big Image) and write directly into file (excatly blob - on azure). Somebody know how to do that (any free library?) I've searched google but no answers (maybe wrong question - my english is poor).

Upvotes: 1

Views: 473

Answers (2)

Eli Algranti
Eli Algranti

Reputation: 9007

I'm not aware of any image libraries that will do the encoding into BMP format on the fly so I'm afraid you'll have to implement your own. Fortunately the BMP format is very simple when no compression is used and not very difficult with RLE compression. It's basically a header followed by the raw bytes of the image pixels, line after line.

This means you're going to have to load all the images in a line (if your target image is say 30 by 40 images, you'll need to load 30.) Unless your input images are also in BMP format and you don't mind creating a custom reader.

You can get the BMP file format by typing "BMP Format" in Google (wikipedia has it as well.)

Upvotes: 0

Pavel Vladov
Pavel Vladov

Reputation: 4837

If you are talking about a "bmp" file, you can do this by directly writing data to a file stream in the Bitmap file format. It's pretty simple, actually the "bmp" is the simplest image format, so I doubt you will have any difficulties. Here are 2 useful articles that explain the bitmap file format in details:

BMP file format in Wikipedia

Microsoft Windows Bitmap

Upvotes: 1

Related Questions