I may need help to figure out how to submit the process below. I need to write a monochrome BMP file. The code below (its from: How to save a monochrome image as bmp in Windows C ++? ) Looks like to be able to do this. I am now fixated on how to convert, std::bitsetor preferably boost::dynamic_bitsetinto this format byte*. All my attempts so far have failed, I could not write something like an 8x8 validation pattern in BMP. The process creates a BMP and is readable in Photoshop, but the content is a mess. Therefore, any suggestions on how to solve this problem are appreciated!
Save1BppImage(byte* ImageData, const char* filename, long w, long h){
int bitmap_dx = w;
int bitmap_dy = h;
std::ofstream file(filename, std::ios::binary | std::ios::trunc);
if(!file) return;
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER * infoHeader;
infoHeader = (BITMAPINFOHEADER*) malloc(sizeof(BITMAPINFOHEADER) );
RGBQUAD bl = {0,0,0,0};
RGBQUAD wh = {0xff,0xff,0xff,0xff};
fileHeader.bfType = 0x4d42;
fileHeader.bfSize = 0;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + (sizeof(BITMAPINFOHEADER));
infoHeader->biSize = (sizeof(BITMAPINFOHEADER) );
infoHeader->biWidth = bitmap_dx;
infoHeader->biHeight = bitmap_dy;
infoHeader->biPlanes = 1;
infoHeader->biBitCount = 1;
infoHeader->biCompression = BI_RGB;
infoHeader->biSizeImage = 0;
infoHeader->biXPelsPerMeter = 0;
infoHeader->biYPelsPerMeter = 0;
infoHeader->biClrUsed = 2;
infoHeader->biClrImportant = 2;
file.write((char*)&fileHeader, sizeof(fileHeader));
file.write((char*)infoHeader, (sizeof(BITMAPINFOHEADER) ));
file.write((char*)&bl,sizeof(bl));
file.write((char*)&wh,sizeof(wh));
int bytes = (w/8) * h ;
file.write((const char*)ImageData, bytes);
file.close();
}
-edit -
my naive approach was something like this
byte test[64];
for(unsigned int i=0; i<64; ++i)
if(i % 2)
test[i] = 0;
else
test[i] = 1;
Save1BppImage(test, "C:/bitmap.bmp", 8, 8);