I have a question on CreateDibSection. Im creating a section of 32 bpp and im using a function we can say "PutPixel" that simple makes:

void PutPixel(DWORD x, DWORD y, COLORREF Colour)

g_lpBMPMem[y * BmpWidth + x] = Colour;


The thing is that CreateDIBSection is inverting the colours bytes, i mean if a do a "PutPixel(50, 50, RGB(30,0, 61));", the RED value is considered the BLUE and viceversa. Why this? :roll:

Onother thing is if i pass a positive value to the Height parameter of BITMAPINFO structure when i create the section, then when i BLT the DIB it is horizontal inverted, so i have to pass a negative one. Again, why this? :roll:
Posted on 2004-10-28 12:56:08 by Ateneo
Aside the fact that writing a PutPixel procedure defeats the whole point of using CreateDIBSection (it was just an example, I know :) ), what you're describing are not really problems, but the documented functionality of this API call...

1. DIB bitmaps created with the BI_RGB flag use the RGBQUAD format instead of COLORREF. It works just like you described. I undestand you can change this behavior by specifying your own color format (BI_BITFIELDS), but I found it not to work at all unless you happen to describe an exact equivalent to BI_RGB, at least under Win9X. Maybe in up-to-date Windows versions it works like it should. :roll: :-D

2. It's a convention. A positive value means you want to create a bottom-up bitmap, a negative value for a top-down. See this quote from MSDN:

Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.

If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.

Some links:

Hope that helps. :)
Posted on 2004-10-28 14:02:55 by QvasiModo
yes now i got it. Thanks
Posted on 2004-10-28 14:56:32 by Ateneo