Weird Bitmap Header

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Weird Bitmap Header

 
0
  #1
Mar 4th, 2009
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:
  1.  
  2. typedef struct
  3. {
  4. unsigned char B;
  5. unsigned char M;
  6. unsigned int Size;
  7. short Reserved1;
  8. short Reserved2;
  9. unsigned int Offset;
  10.  
  11. unsigned int HeaderSize;
  12. unsigned int Width;
  13. unsigned int Height;
  14. unsigned short Planes;
  15. unsigned short Bits;
  16. unsigned int Compression;
  17. unsigned int ImageSize;
  18. int XPixelsPerMeter;
  19. int YPixelsPerMeter;
  20. unsigned int ColorsInPalette;
  21. unsigned int ColorImportant;
  22. } BHeader;
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Weird Bitmap Header

 
1
  #2
Mar 4th, 2009
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.
"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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Re: Weird Bitmap Header

 
0
  #3
Mar 4th, 2009
Thanks! It works now.
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC