1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| void createBmp(BYTE* imageTab, int height, int width){
RGBQUAD palPalEntry[256];
for (int i = 0; i < 256; i++) {
palPalEntry[i].rgbBlue = (BYTE)i;
palPalEntry[i].rgbGreen = (BYTE)i;
palPalEntry[i].rgbRed = (BYTE)i;
palPalEntry[i].rgbReserved = (BYTE)0;
}
BITMAPINFO RGB8BitsBITMAPINFO;
ZeroMemory(&RGB8BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB8BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB8BitsBITMAPINFO.bmiHeader.biWidth = Height;
RGB8BitsBITMAPINFO.bmiHeader.biHeight = Width;
RGB8BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB8BitsBITMAPINFO.bmiHeader.biBitCount = 8;
//RGB8BitsBITMAPINFO.bmiHeader.biCompression = BI_RGB;
//bimap file header in order to write bmp file
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4d42; //bmp
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + 256 * sizeof(RGBQUAD) + (width*height);
//write into file
FILE *mStream = NULL;
if((mStream = fopen("CCD.bmp", "wb")))
{
fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);
fwrite(&(RGB8BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);
fwrite(imageTab, width*height, 1, mStream);
fclose(mStream);
}
} |
Partager