Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » StaticImage cannot show BMP file
Re: StaticImage cannot show BMP file [message #43614 is a reply to message #43610] Sat, 13 September 2014 20:18 Go to previous messageGo to previous message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Hi, your struct BMP_FILEHEADER has the wrong memory layout,
it must be "packed" meaning no gaps between the members.

You have:
struct BMP_FILEHEADER {
	word    bfType;       2 bytes
gap-------------------------->2 bytes
	dword   bfSize;       4 bytes
	word    bfReserved1;  2 bytes
	word    bfReserved2;  2 bytes
	dword   bfOffBits;    4 bytes

In sum                       16 bytes



but the Microsoft spec requires that no gap between members exists (in the time defining the struct it was traded not to "waste" space often).

So it must be
struct BMP_FILEHEADER {
	word    bfType;       2 bytes
	dword   bfSize;       4 bytes
	word    bfReserved1;  2 bytes
	word    bfReserved2;  2 bytes
	dword   bfOffBits;    4 bytes

In sum                       14 bytes


Your change to get it work (bfOffBits changing type) is not right, because
you have still bfSize member at invalid memory position.

The upp code tries to get the "packed" aligment by using for Microsoft Compiler

#ifdef COMPILER_MSC
#pragma pack(push, 1)
#endif

or for GCC

#ifdef COMPILER_GCC
__attribute__((packed))
#endif

You can check if the right compiler #define is defined.
Or your compiler ignores this directive for whatever reason.

Hope it helps.

[Updated on: Sat, 13 September 2014 23:30]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: From XSD to XML
Next Topic: HowTo bind StaticImage to SQL
Goto Forum:
  


Current Time: Thu Jun 13 16:42:56 CEST 2024

Total time taken to generate the page: 0.02814 seconds