I watched the solution of this problem on msdn and here: C ++ How to create a bitmap file
It creates a file with the extension .bmp but there is nothing in the description, the file says that it is damaged. read the title, looked like that. tried to copy from bmp to bmp, if you completely copy bmpFileHeader and bmpInfoHeader then it works. Also tried to do some more manipulations, flip flip. Looks like I'm doing something wrong with the headlines.
BITMAPFILEHEADER bmpFileHeader = { 0 }; BITMAPINFOHEADER bmpInfoHeader = { 0 }; RGBQUAD RGBcolor; for (size_t i = 0; i < height*width; ++i) image[i].reserved = 0; bmpFileHeader.bfType = 0x4d42; bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfoHeader.biWidth = width; bmpInfoHeader.biHeight = height; bmpInfoHeader.biSizeImage = (DWORD)(bmpInfoHeader.biWidth * bmpInfoHeader.biHeight); bmpInfoHeader.biPlanes = 1; bmpInfoHeader.biBitCount = 8; bmpInfoHeader.biCompression = BI_RGB; bmpInfoHeader.biXPelsPerMeter = bmpInfoHeader.biYPelsPerMeter = 2000; bmpFileHeader.bfSize = sizeof(BITMAPFILEHEADER)+bmpInfoHeader.biSize + bmpInfoHeader.biSizeImage; bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + bmpInfoHeader.biSize + sizeof(RGBQUAD); for (size_t i = 0; i < height * width; ++i){ fwrite(&image[i], sizeof(RGBQUAD), 1, output); } typedef struct RGB{ BYTE rgbtBlue; BYTE rgbtGreen; BYTE rgbtRed; BYTE reserved; };