Original Post
Hi guys,
I'm trying to load in a Windows Bitmap (BMP) file in for some processing (not displaying). However, code on the net that I've found all uses Windows, so I took on the task of coding the loader myself. I found a file specification for BMP and made two structures, like so:
This is used in a class called CBitmap, which has a LoadFile method, like so:
bmpInfo and bmpHeader are private members of CBitmap, and hold the header and info header of the bitmap.
Now, everything works fine, but the problem is, it isn't loading it correctly from the file. I'm absolutely positive I've messed up on my file types in the structs, but I'm not sure how, because a long is 4 bytes, and a short is 2 bytes, and I've followed the specification to the letter. So, if anyone can help me, it would be greatly appreciated.
And yes, I realize I haven't loaded the whole BMP in, just the headers. I'm just trying to load these first before attempting to tackle the rest of it. No point in trying to load a whole file if you can't get the headers right, you know?
[edited by - UBC_Wiskatos on July 17, 2002 3:20:27 PM]
struct BitmapHeader
{
long bfType;
short bfSize;
long bfReserved1;
long bfReserved2;
short bfOffBits;
};
struct BitmapInfo
{
long biSize;
long biWidth;
long biHeight;
short biPlanes;
short biBitCount;
long biCompression;
long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant;
};
void LoadFile(char filename[])
{
ifstream bmpFile;
bmpFile.open(filename, ios::in|ios::binary|ios::ate);
bmpFile.seekg (0,ios::beg);
bmpFile.read((char *)(&bmpHeader), sizeof(bmpHeader));
bmpFile.read((char *)(&bmpInfo), sizeof(bmpInfo));
bmpFile.close();
}
