Hello, I was wondering if guys could help me out here, im trying to manually a load a bitmap file in a C++ program but am a little confused. After searching through various tutorials on this subject I dont seem to be doing anything wrong but for some reason the values I am getting in my bitmap headers seem to be wrong (or maybe its just me).
Here is the code i have to read a bitmap, admitedly it is not complete as it only opens the file and reads in to my "custom" BitmapFileHeader and BitmapInfoHeader structures.
Here is the list of values that shows up when "stepping through" my code with the vs debugger:Code://structure to contain bitmap file header information. It is the same as the win32 version except its my own.. if that makes sense struct BitmapFileHeader { unsigned short Type; unsigned int Size; unsigned short Reserved1; unsigned short Reserved2; unsigned int OffBits; }; struct BitmapInfoHeader { unsigned int Size; long Width; long Height; unsigned short Planes; unsigned short BitCount; unsigned int Compression; unsigned int SizeImage; long XPelsPerMeter; long YPelsPerMeter; unsigned int ClrUsed; unsigned int ClrImrportant; }; // Read bitmap file void Bitmap::Read( const char* file ) { // open file for reading std::ifstream f( file, std::ios::binary ); if ( !f.is_open( ) ) { std::cout << "Error: File not found."; f.close( ); } // read in the file and info headers f.read( reinterpret_cast<char*>(&mFileHeader), sizeof( BitmapFileHeader ) ); f.read( reinterpret_cast<char*>(&mInfoHeader), sizeof( BitmapInfoHeader ) ); }
mFileHeader.Type = 19778 < (Thats probably the only value that looks correct to me.. when cast into char* it produces "BM")
mFileHeader.Size = 0
mFileHeader.Reserved1 = 0
mFileHeader.Reserved2 = 54
mFileHeader.OffBits = 2621440
mInfoHeader.Size = 131072
mInfoHeader.Width = 131072
mInfoHeader.Height = 65536
mInfoHeader.Planes = 24
mInfoHeader.BitCount = 0
mInfoHeader.Compression = 1048576
mInfoHeader.SizeImage = 0
mInfoHeader.XPelsPerMeter = 0
mInfoHeader.YPelsPerMeter = 0
mInfoHeader.ClrUsed = 0
mInfoHeader.ClrImrportant = 0
Im not sure but i think the compression might be the problem, however i did try another type of .bmp that had compression 0 but still had the same problems so maybe not (and im guessing compression only deals with the actual data, not the headers).
Anywho, Thanks in advance.
~CC
PS: The image I am loading is a simple 2x2 24-bit .bmp created with windows 7 version of paint. Unless im a mistaken the mInfoHeader.Width/Height should be 2 x 2
not 131072x65536, you get my point :P



LinkBack URL
About LinkBacks



