c++cimagegraphicsbmp

Writing BMP image in pure c/c++ without other libraries


In my algorithm, I need to create an information output. I need to write a boolean matrix into a bmp file. It must be a monocromic image, where pixels are white if the matrix on such element is true. Main problem is the bmp header and how to write this.


Solution

  • Without the use of any other library you can look at the BMP file format. I've implemented it in the past and it can be done without too much work.

    Bitmap-File Structures

    Each bitmap file contains a bitmap-file header, a bitmap-information header, a color table, and an array of bytes that defines the bitmap bits. The file has the following form:

    BITMAPFILEHEADER bmfh;
    BITMAPINFOHEADER bmih;
    RGBQUAD aColors[];
    BYTE aBitmapBits[];

    ... see the file format for more details