Original Post
A while back I took a few different bitmaps and put them into one file (each section of the file containing: width,height,raw image data) I''m trying to take each image in the file and convert it back to a bitmap. I never altered the raw image data when i took it from the bitmap (so the padding to establish a DWORD boundary for each line should still be there). I am able to create the bitmap, but the entire image is skewed (diagonally), and the colors are messed up. If i subtract one from the bitmap width in the bitmap header, the image is still skewed but the colors are ok. (forget that its inverted... im just trying to get it to look right first) Im lost.. any ideas??
the only time it works is when the file doesn''t need DWORD boundary padding... like an 800x600 image.. so it has definitely something to do with that.. but i never altered the data!!
here is the ghetto function i use to create the bmp:
Help!! Thanks!
int CreateBmp(LPCSTR file_name, int width, int height, BYTE * data, long data_size = 0)
{
BITMAPFILEHEADER header;
BITMAPINFOHEADER info;
header.bfReserved1 = 0;
header.bfReserved2 = 0;
header.bfType = 19778;
LONG byteWidth, padWidth;
byteWidth=padWidth=(LONG)((float)width*(float)24/8.0);
while(padWidth%4!= 0)
padWidth++;
info.biSize = 40;
info.biWidth = width;
info.biHeight = height;
info.biPlanes = 1;
info.biBitCount = 24;
info.biCompression = BI_RGB;
info.biSizeImage = data_size;
info.biXPelsPerMeter = 0;
info.biYPelsPerMeter = 0;
info.biClrUsed = 0;
info.biClrImportant = 0;
fstream file;
file.open(file_name, ios::out | ios::binary);
header.bfOffBits = 0;
file.write((char *)&header, sizeof(header));
file.write((char *)&info,sizeof(info));
//GET OFFBITS
long offbits;
offbits = file.tellp();
//WRITE DATA
file.write((char *)data, data_size);
//SET INFO
header.bfOffBits = offbits;
//GET TOTAL FILE SIZE
long filesize;
filesize = file.tellp();
header.bfSize = filesize;
file.seekp(0,ios::beg); //SEEK BEGINNING
file.write((char *)&header, sizeof(header)); //REWRITE HEADER
file.close(); //DELETE FILE
return TRUE;
}