| | |
Weird Bitmap Header
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi, I'm reading the header from bitmaps. When I add up everything in a struct I've made, it comes out to 54 bytes. When I do a sizeof(BHeader), it says it's 56 bytes. It adds two null bytes after the B and the M when I save a header to a file. It's very weird. Please help.
Here's my struct:
Here's my struct:
C++ Syntax (Toggle Plain Text)
typedef struct { unsigned char B; unsigned char M; unsigned int Size; short Reserved1; short Reserved2; unsigned int Offset; unsigned int HeaderSize; unsigned int Width; unsigned int Height; unsigned short Planes; unsigned short Bits; unsigned int Compression; unsigned int ImageSize; int XPixelsPerMeter; int YPixelsPerMeter; unsigned int ColorsInPalette; unsigned int ColorImportant; } BHeader;
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
--Martin Golding
The compiler is aligning the struct elements on word (4byte) boundaries, thus the two empty bytes between your char's and the next element.
You might look up what the pack pragma will do for you, or other compiler options.
You might look up what the pack pragma will do for you, or other compiler options.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Other Threads in the C++ Forum
- Previous Thread: function to add to strings
- Next Thread: std::string and exceptions in constructor
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






