win32 CreateBitmap

The CreateBitmap function creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel).

HBITMAP CreateBitmap(
  __in  int nWidth,
  __in  int nHeight,
  __in  UINT cPlanes,
  __in  UINT cBitsPerPel,
  __in  const VOID *lpvBits
);

Parameters

nWidth [in]
The bitmap width, in pixels.

nHeight [in]
The bitmap height, in pixels.

cPlanes [in]
The number of color planes used by the device.

cBitsPerPel [in]
The number of bits required to identify the color of a single pixel.

lpvBits [in]
A pointer to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the contents of the new bitmap is undefined.

Return Value

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

If the function fails, the return value is NULL.

This function can return the following value.

扫描二维码关注公众号,回复: 1874621 查看本文章
Return code Description
ERROR_INVALID_BITMAP The calculated size of the bitmap is less than zero.

Remarks

The CreateBitmap function creates a device-dependent bitmap.

After a bitmap is created, it can be selected into a device context by calling the SelectObject function. However, the bitmap can only be selected into a device context if the bitmap and the DC have the same format.

The CreateBitmap function can be used to create color bitmaps. However, for performance reasons applications should use CreateBitmap to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color bitmap returned from CreateBitmap is selected into a device context, the system checks that the bitmap matches the format of the device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns a bitmap that has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color bitmap from CreateCompatibleBitmap than with a color bitmap returned from CreateBitmap.

If the bitmap is monochrome, zeros represent the foreground color and ones represent the background color for the destination device context.

If an application sets the nWidth or nHeight parameters to zero, CreateBitmap returns the handle to a 1-by-1 pixel, monochrome bitmap.

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

Color Plane是什么东西?

再附上MSDN的解释:
Current number of color planes used in the video display. A color plane is another way to represent pixel colors; instead of assigning a single RGB value to each a pixel, color planes separate the graphic into each of the primary color components (red, green, and blue), and store them in their own planes. This allows for greater color depths on 8 and 16 bit video systems. Present graphics systems have the bitwidth large enough to store color depth information, making only one color plane necessary.

Color Plane是VGA时代的历史遗迹,不用管它,设为1即可。

color plane和color palette 不是一个东西
http://en.wikipedia.org/wiki/Bit_plane
http://topic.csdn.net/t/20050329/16/3891448.html
因为这个东西已经淘汰了,所以可以不用管它,否则一些过时的知识反而增加你的负担;真要知道,必须了解EGA/VGA显示接口,当时的EGA接口是数字式的(相对于现在的VGA显示接口是模拟式的),现在已经找不到了,也不用了,只有在很老的计算机书上才能看到。
For example, for 16-bit data representation there are 16 bit-planes: the first bit-plane contains the set of the most significant bit and the 16th contains the least significant bit.
其实, 你理解成指定这个值主要是关联到数字式显示接口就行了, 它的意义和现在的模拟接口指定的UINT cBitsPerPel是一样的.
http://www.gamedev.net/topic/563156-what-is-a-color-plane/

猜你喜欢

转载自blog.csdn.net/wowocpp/article/details/80908509