Make sense to you?
Yes.
When you marshal between managed and unmanaged code this type of alignment
issue can easily cause you headaches.
The correct calculation of the offset for .bfOffBits is important. I have
seen code on the internet that doesn't even look at it.
It assumes that the structures are laid out one after the other with the
bitmap's bits following the structures, which is not necessarily correct.
If you want to use memory mapped files for very large bitmaps and pass a
hSection to a memory mapped file
and dwOffset for the bits to CreateDIBSection, the documentation states that
the dwOffset passed must be located
on a DWORD boundary.
If you do not align on a DWORD boundary, the bits would be located at an
offset that is off by 2 bytes.
CreateDIBSection would fail!
For a 16bpp, 24bpp or 32bpp bitmap:
BITMAPFILEHEADER 14 bytes
BITMAPINFOHEADER 40 bytes
bits <---------------------54 this offset is off by two.
bits<----------------------56 this offset is aligned on a DWORD boundary.
If you loaded a bitmap that was aligned this way and did not check the
..bfOffBits offset,
CreateDIBSection would fail!
The moral to the above is assume nothing. Always check!
While searching the Internet I noticed that you have been helping people
for years!
I am happy to provide assistance.