This function creates a device-independent bitmap (DIB) that applications can write to directly. The function returns a handle to the bitmap.
At a Glance
Header file: | Wingdi.h |
Windows CE versions: | 1.0 and later |
Syntax
HBITMAP CreateDIBSection(HDC hdc, const BITMAPINFO *pbmi,
UINT iUsage, void *ppvBits, HANDLE hSection, DWORD dwOffset);
Parameters
hdc
[in] Handle to a device context. If the value of iUsage is DIB_PAL_COLORS, the function uses this device context's logical palette to initialize the device-independent bitmap’s colors.
pbmi
[in] Pointer to a BITMAPINFO structure that specifies various attributes of the device-independent bitmap, including the bitmap’s dimensions and colors.
iUsage
[in] Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure pointed to by pbmi (either logical palette indexes or literal RGB values). The following values are defined:
Value | Description |
DIB_RGB_COLORS | The BITMAPINFO structure contains an array of literal RGB values. Specify this value except when an 8 bpp bitmap is used. |
DIB_PAL_COLORS | Specify this value when an 8 bbp bitmap is used. When DIB_PAL_COLORS is used, the system ignores the bmiColors member of the BITMAPINFO structure and the dwOffset parameter. Set dwOffset to zero and the hSection parameter to NULL. |
ppvBits
[in] Pointer to a variable that receives a pointer to the location of the device-independent bitmap’s bit values.
hSection
[in] Unsupported; set to NULL.
dwOffset
[in] Ignored.
Return Values
A handle to the newly created device-independent bitmap indicates success, and *ppvBits points to the bitmap’s bit values.
NULL indicates failure, and *ppvBits is NULL.
To get extended error information, call GetLastError.
Remarks
As noted above, if hSection is NULL, the system allocates memory for the device-independent bitmap. The system closes the handle to that memory when you later delete the device-independent bitmap by calling the DeleteObject function. If hSection is not NULL, you must close the hSection memory handle yourself after calling DeleteObject to delete the bitmap.
In Windows CE versions 2.0 and later, the BITMAPINFO structure must include a color table if the images are palettized (usually 1,2,4, and 8 bpp formats). For 16bpp or 32bpp non-palettized images, the color table must be three entries long; the entries must specify the values of the red, green, and blue bitmasks. Also, the biCompression field in the BITMAPINFOHEADER structure should be set to BI_BITFIELDS. BI_RBG is not supported for these bit depths. GDI ignores the color table for 24 bpp images; their pixels must be stored in Blue-Green-Red (BGR) format.
In Windows CE versions 1.0 and 1.01, the BITMAPINFO structure pointed to by the pbmi parameter must specify 1 or 2 bits per pixel.
See Also