Original Post
Hey,
I''m trying to output to a bitmap file, but it ain''t working! Paint tells me it''s not a valid bitmap file, and photoshop tells me it can''t parse the file.
I''m using the format described at:
http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/BMP.txt
and this is the code i''m using to do it.
Hope that source displays ok.
Any help greatly appreciated!
Thanks.
// create headers
BITMAPFILEHEADER bmfheader;
BITMAPINFO bmi;
// init headers
bmfheader.bfType = (''M'' * 256) + ''B'';
bmfheader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO)
+ 3 * height * (width + (width % 4));
bmfheader.bfReserved1 = 0;
bmfheader.bfReserved2 = 0;
bmfheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO);
bmi.bmiColors[0] = 0;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = 0;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
// write headers
outputStm << bmfheader.bfType << bmfheader.bfSize << bmfheader.bfReserved1 << bmfheader.bfReserved2 << bmfheader.bfOffBits;
outputStm << bmi.bmiHeader.biSize << bmi.bmiHeader.biWidth
<< bmi.bmiHeader.biHeight << bmi.bmiHeader.biPlanes << bmi.bmiHeader.biBitCount
<< bmi.bmiHeader.biCompression << bmi.bmiHeader.biSizeImage
<< bmi.bmiHeader.biXPelsPerMeter << bmi.bmiHeader.biYPelsPerMeter
<< bmi.bmiHeader.biClrUsed << bmi.bmiHeader.biClrImportant; outputStm << bmi.bmiColors[0];
// Write each pixel
for (int y = height-1; y >= 0; y--)
{
for (int x = 0; x < width; x++)
{
outputStm << blue[index(x,y)] << green[index(x,y)]
<< red[index(x,y)];
}
for ( int n = 0; n < width % 4; ++n ) // set scanline on a LONG boundary
{
outputStm << ''\0'';
}
}