CBitmapInfoPtr Class |
Description
The CBitmapInfoPtr class simplifies the creation and use of the BITMAPINFO structure. The BITMAPINFO structure is used in the GetDIBits and SetDIBits Window API functions.
Remarks
The traditional BITMAPINFO structure is defined like this.
typedef struct tagBITMAPINFO { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1]; } BITMAPINFO, *PBITMAPINFO;
The thing that makes the traditional BITMAPINFO structure difficult to use is that the bmiColors member is an array. This array has a different number of elements depending on the color depth of the Bitmap. As a result the bmiColors member needs to be created dynamically on the heap before the structure can be declared. CBitmapInfoPtr takes care of these details for for us.
To use CBitmapInfoPtr, simply construct its object by providing a handle (HBITMAP) to the bitmap in its constructor. The CBitmapInfoPtr object can then be used anywhere in place of a pointer to BITMAPINFO. The following example demonstrates the use of CBitmapInfoPtr.
// Create our LPBITMAPINFO object CBitmapInfoPtr pbmi(hbmSource); // Create the DC for GetDIBits to use CDC MemDC = CreateCompatibleDC(NULL); // Use GetDIBits to create a DIB from our DDB, and extract the colour data MemDC.GetDIBits(hbmSource, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
Summary Information
Header file | gdi.h |
Win32/64 support | Yes |
WinCE support | Yes |