Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading header from BMP

Status
Not open for further replies.

szcygan

Programmer
Jul 18, 2001
19
0
0
PL
The header of a bmp file is supposed to be:

typedef struct
{
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;

I'm reading this header like this:

fread(&header, sizeof(BITMAPFILEHEADER), 1, fp)

and it seems to be working fine. The bfType is correct, but everything else is... not right. bfSize = 0 or 3 or something like that, bfOffBits is 7 digits long etc.. Is this maybe a problem with structure aligment, or something else?

Please help!
 
try to see if bfType is 'BM' or 'MB'. If is 'MB' then there is some problems with number little/big endian formats.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thanks Ion.

It is 'MB'.. How can I solve this problem? (I'm rather fresh with Visual C++)
 
in this case you should invert each int and shortint

short int is 2 bytes, for example AB, change it to BA.
int or long is 4 bytes, for example ABCD, change it to DCBA. Use unions:

class inverter
{
public:
union
{
int x;
char c[4];
};
void invert()
{swap there the order of characetrs in c}
};
inverter a;
a.x = = younumber;
a.invert();
yournumebr = a.x;

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top