CreateDIBitmap

The CreateDIBitmap function creates a device-dependent bitmap (DDB) from a device-independent bitmap (DIB) and, optionally, sets the bitmap bits.

HBITMAP CreateDIBitmap(
  HDC hdc,                  // handle to device context
  CONST BITMAPINFOHEADER *lpbmih,  // pointer to bitmap size and
                                   // format data
  DWORD fdwInit,            // initialization flag
  CONST VOID *lpbInit,      // pointer to initialization data
  CONST BITMAPINFO *lpbmi,  // pointer to bitmap color-format data
  UINT fuUsage              // color-data usage
);
 

Parameters

hdc
Handle to a device context.
lpbmih
Pointer to a bitmap information header structure, which may be one of the following:
Operating System Bitmap Information Header
Windows NT 3.51 and earlier BITMAPINFOHEADER
Windows NT 4.0 and Windows 95 BITMAPV4HEADER
Windows NT 5.0 and Windows 98 BITMAPV5HEADER

If fdwInit is CBM_INIT, the function uses the bitmap information header structure to obtain the desired width and height of the bitmap as well as other information. Note that a positive value for the height indicates a bottom-up DIB while a negative value for the height indicates a top-down DIB. This scenario is compatible with the CreateDIBitmap function.

fdwInit
A set of bit flags that specify how the system initializes the bitmap bits.

The following bit flag constant is defined:
Value Meaning
CBM_INIT If this flag is set, the system uses the data pointed to by the lpbInit and lpbmi parameters to initialize the bitmap's bits.

If this flag is clear, the data pointed to by those parameters is not used.


If fdwInit is zero, the system does not initialize the bitmap's bits.

lpbInit
Pointer to an array of bytes containing the initial bitmap data. The format of the data depends on the biBitCount member of the BITMAPINFO structure to which the lpbmi parameter points.
lpbmi
Pointer to a BITMAPINFO structure that describes the dimensions and color format of the array pointed to by the lpbInit parameter.
fuUsage
Specifies whether the bmiColors member of the BITMAPINFO structure was initialized and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or palette indexes. The fuUsage parameter must be one of the following values.
Value Meaning
DIB_PAL_COLORS A color table is provided and consists of an array of 16-bit indexes into the logical palette of the device context into which the bitmap is to be selected.
DIB_RGB_COLORS A color table is provided and contains literal RGB values.

Return Values

If the function succeeds, the return value is a handle to the bitmap.

If the function fails, the return value is NULL.

Windows NT: To get extended error information, call GetLastError.

Remarks

The CBM_CREATDIB flag for the fdwInit parameter is no longer supported.

When you no longer need the bitmap, call the DeleteObject function to delete it.

ICM: The fuUsage parameter specifies whether the bmiColors member of BITMAPINFO pointed at by the lpbmi parameter does or does not contain color information. If bmiColors does not contain color information, no color management is performed for the bitmap. The bmiHeader member of BITMAPINFO must contain either BITMAPV4HEADER or BITMAPV5HEADER for color management to be enabled. The contents of the resulting bitmap are not color matched after the bitmap has been created.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in wingdi.h.
  Import Library: Use gdi32.lib.

See Also

Bitmaps Overview, Bitmap Functions, BITMAPINFOHEADER, BITMAPINFO, DeleteObject, GetDeviceCaps, GetSystemPaletteEntries, SelectObject