Hi
I'm having problems with CreateDIBSection. This is my code:


.data
bmi label BITMAPINFO ;Used for raw bitmap access (bitmap dc)
BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,,,1,32,BI_BITFIELDS,0,0,0,0,0>
dd 000000FFh ;red mask
dd 0000FF00h ;green mask
dd 00FF0000h ;blue mask

.code
invoke CreateDIBSection,bmpdc,offset bmi,DIB_RGB_COLORS,offset pbits,0,0

But CreateDIBSection always returns zero. If I use BI_RGB instead of BI_BITFIELDS, or if I use this bitmasks for the colors, it works:


bmi label BITMAPINFO ;Used for raw bitmap access (bitmap dc)
BITMAPINFOHEADER <sizeof BITMAPINFOHEADER,,,1,32,BI_BITFIELDS,0,0,0,0,0>
dd 00FF0000h ;blue mask (reversed)
dd 0000FF00h ;green mask
dd 000000FFh ;red mask (reversed)

The bmpdc device context was created with CreateCompatibleDC, passing it a dc handle from an existing window. However, calling CreateCompatibleDC,NULL does not seem to make any difference.
Is it a bug in Windows 98, or am I doing something wrong? As I wrote in other post, am new at GDI, so feel free to suggest (and criticize :) )
Posted on 2003-07-18 18:34:34 by QvasiModo
I have never worked with BI_BITFIELDS, but if it works the second way, I think this is the reason:


RGB macro red,green,blue
xor eax,eax
mov ah,blue ; see, it goes leftmost
shl eax,8
mov ah,green ; green in in the middle
mov al,red ; red is rightmost
endm

so, you have this 'Hex': 00BBGGRRh
why exactly do you want to use BI_BITFIELDS? What does it make apart from specifying that it's not compressed (just like RGB)? I'm not entirely sure, but I think if you use BI_RGB, you will win hardware acceleration from the video card, when BitBlt-ing.

CreateCompatibleDC will accept 0 as parameter, but CreateCompatibleBitmap will create a monochromatic bitmap (black/white) if you do so.
Posted on 2003-07-19 00:34:09 by Ultrano

I have never worked with BI_BITFIELDS, but if it works the second way, I think this is the reason:


RGB macro red,green,blue
xor eax,eax
mov ah,blue ; see, it goes leftmost
shl eax,8
mov ah,green ; green in in the middle
mov al,red ; red is rightmost
endm

so, you have this 'Hex': 00BBGGRRh
why exactly do you want to use BI_BITFIELDS? What does it make apart from specifying that it's not compressed (just like RGB)? I'm not entirely sure, but I think if you use BI_RGB, you will win hardware acceleration from the video card, when BitBlt-ing.

CreateCompatibleDC will accept 0 as parameter, but CreateCompatibleBitmap will create a monochromatic bitmap (black/white) if you do so.


dd 000000FFh ;red mask
dd 0000FF00h ;green mask
dd 00FF0000h ;blue mask
that should make
00BBGGRRh
so the color mask would be correct... :confused: it's only with a reversed color mask that it seems to work. I checked with a debugger, and the color mask used by the bitmap has the blue and red values exchanged. I need the bitmap to have the same color mask as the values returned by GetSysColor.

Unfortunately, I have to ue BI_BITFIELDS, since some Windows versions don't support BI_RGB, there is no other reason (I think BI_RGB is much better). And I need raw bitmap access, since what I want to do can't be done with BitBlt. Specifically, I want to replace every color in a bitmap with the corresponding pixel in a second bitmap.

I didn't know that about CreateCompatibleBitmap... Let's just hope that CreateDIBSection doesn't have a similar problem :)
Posted on 2003-07-19 11:51:13 by QvasiModo
Perhaps bitmap images are not supposed to use the COLORREF format?
Posted on 2003-07-19 12:05:43 by QvasiModo