Sunday, April 25, 2004 5:47 PM
by
jsirois
Using GetObject to find out the pixel format of a bitmap.
GDI has a method call GetObject which can be used to get information about a GDI object. On Windows CE you can use GetObject to get the pixel format for any bitmap by passing in a DIBSECTION instead of a BITMAP. Here's an example:
DIBSECTION ds;
HDC hdc = GetDC(NULL);
HGDIOBJ bmp = GetCurrentObject(hdc, OBJ_BITMAP);
GetObject(bmp, sizeof (ds), &ds);
Obviously, in production code you'd want to actually check return values, but this is the general idea. If (ds.dsBm.bmBitsPixel > 8) and (ds.dsBmih.biCompression == BI_BITFILEDS), ds.dsBitfields will contain the bit masks for the three color channels. If ds.dsBmih.biCompression is BI_RGB, the bitmap is either an RGB surface, or a palettized surface and ds.dsBitfields will be 0.
This behavior makes it relatively easy to create a DIB section that has the same pixel format as another bitmap.
FYI: I don't believe this works on the desktop.