CreateDIBSection

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function creates a device-independent bitmap (DIB) that applications can write to directly. The function returns a handle to the bitmap.

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 bit masks or a palette depending on the value of the biCompression member of the structure. These values are used when rendering the bitmap.

    This value can be specified along with any bit count.

    DIB_PAL_COLORS

    The BITMAPINFO.bmiColors array is ignored, and the destination palette is used when rendering the bitmap.

    This value can only be specified with an 8-bpp bitmap.

  • ppvBits
    [in] Pointer to a variable that receives a pointer to the location of the device-independent bitmap's bit values.
  • hSection
    [in] Set this parameter to NULL.
  • dwOffset
    [in] Ignored.

Return Value

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

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.

In Windows CE 2.0 and later, the BITMAPINFO structure must include a color table if the images are palletized (usually 1-, 2-, 4-, and 8-bpp formats).

For 16-bpp or 32-bpp non-palletized 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 member in the BITMAPINFOHEADER structure should be set to BI_BITFIELDS. BI_RGB 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.

Windows Embedded CE does not support 332 bitfields devices.

In Windows CE 1.0 and 1.01, the BITMAPINFO structure pointed to by the pbmi parameter must specify 1 or 2 bits per pixel.

The memory of a DIBSECTION is DWORD-aligned by row.

Requirements

Header windows.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

DeleteObject
GetObject
SelectObject
BITMAPINFO
BITMAPINFOHEADER
GDI Functions