|
-
December 5th, 2011, 01:10 PM
#1
My DIBs are 2 Bytes Short
Hi guys,
I noticed that my DIBs, both saved and copied to the clipboard, are 2 bytes short.
Code:
DWORD dwSize=sizeof(BITMAPINFO)+height*span;
HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,dwSize);
LPBYTE mem=(LPBYTE)GlobalLock(hGlobal);
...
// fill in BITMAPINFO
BITMAPINFO* bmi=(BITMAPINFO*)mem;
...
// copy bits
LPBYTE bits=mem+sizeof(BITMAPINFO)+2;
// if I don't add the +2 the colors are shifted
...
Where are those 2 bytes coming from ?
My filesize is always 2 bytes smaller than the same bitmap saved in Photoshop, and if I copy to clipboard the colors are shifted by two bytes (red is blue, green is red, blue is green.)
Thanks
-
December 5th, 2011, 01:49 PM
#2
Re: My DIBs are 2 Bytes Short
See this http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx under remarks.
The bitmap data has to be LONG or DWORD aligned (both 32 bits) so I guess that sizeof(BITMAPINFO) is not a multiple of 4 bytes.
-
December 5th, 2011, 07:57 PM
#3
Re: My DIBs are 2 Bytes Short
In addition, " each scan line must be padded with zeros to end on a LONG data-type boundary", so height*span might be wrong if you are using a color table and indices into the color table.
Of course, if you are using RGBQUADs, then height*span is automatically fine.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|