Bytes alignment in Linux
When I saved the data obtained by the camera in BMP format, the bitmapfileheader should have been 14 bytes, but I used sizeof to output its size in 16 bytes, therefore, the problem of byte alignment occurs.
Solution:
Add the following to the definition structure: # Paraga pack (1)
Example:
# Paraga pack (1)
Typedef struct tagbitmapfileheader {
Word bftype;
DWORD bfsize;
Word bfreserved1;
Word bfreserved2;
DWORD bfoffbits;
} Bitmapfileheader;
Or: _ attribute _ (packed ))
Example:
Struct tagbitmapfileheader {
Word bftype; // the flag of BMP, value is "BM"
DWORD bfsize; // size BMP file, unit is bytes
Word bfreserved1; // 0
Word bfreserved2;
DWORD bfoffbits; // must be 54
}__ Attribute _ (packed ));
Typedef struct tagbitmapfileheader bitmapfileheader;
Note: (Information Query)
# Pragma pack (1) Align the struct in 1 byte mode
BMP format also has some other problems, such as the image display will be upside down, BGR and RGB conversion and so on.