win32 CreateBitmap

本文详细介绍了CreateBitmap函数的使用方法及参数含义,包括如何创建位图、设置颜色平面和每像素位数等,并探讨了该函数与CreateCompatibleBitmap的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

Return codeDescription
ERROR_INVALID_BITMAPThe 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.youkuaiyun.com/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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值