Partager via


CBitmap::CreateBitmap

Initializes a device-dependent memory bitmap that has the specified width, height, and bit pattern.

BOOL CreateBitmap( 
   int nWidth, 
   int nHeight, 
   UINT nPlanes, 
   UINT nBitcount, 
   const void* lpBits  
);

Parameters

  • nWidth
    Specifies the width (in pixels) of the bitmap.

  • nHeight
    Specifies the height (in pixels) of the bitmap.

  • nPlanes
    Specifies the number of color planes in the bitmap.

  • nBitcount
    Specifies the number of color bits per display pixel.

  • lpBits
    Points to an array of bytes that contains the initial bitmap bit values. If it is NULL, the new bitmap is left uninitialized.

Return Value

Nonzero if successful; otherwise 0.

Remarks

For a color bitmap, either the nPlanes or nBitcount parameter should be set to 1. If both of these parameters are set to 1, CreateBitmap creates a monochrome bitmap.

Although a bitmap cannot be directly selected for a display device, it can be selected as the current bitmap for a "memory device context" by using CDC::SelectObject and copied to any compatible device context by using the CDC::BitBlt function.

When you finish with the CBitmap object created by the CreateBitmap function, first select the bitmap out of the device context, then delete the CBitmap object.

For more information, see the description of the bmBits field in the BITMAP structure. The BITMAP structure is described under the CBitmap::CreateBitmapIndirect member function.

Requirements

Header: afxwin.h

See Also

Reference

CBitmap Class

Hierarchy Chart

CDC::SelectObject

CGdiObject::DeleteObject

CDC::BitBlt

CreateBitmap