CreateCompatibleBitmap - [Daliy APIs]

CreateCompatibleBitmap

 

该函数创建与指定的设备环境相关的设备兼容的位图。

原型

HBITMAP CreateCompatibleBitmap(HDC hdc,  int nWidth,  int nHeight);

参数

hdc: 设备环境句柄。

nWidth, nHeight:指定位图的宽度和高度,单位为像素。

返回值

   如果函数执行成功,那么返回值是位图的句柄;如果函数执行失败,那么返回值为NULL。若想获取更多错误信息,请调用GetLastError。

备注

   由CreateCompatibleBitmap函数创建的位图的颜色格式与由参数hdc标识的设备的颜色格式匹配。该位图可以选入任意一个与原设备兼容的内存设备环境中。

   由于内存设备环境允许彩色和单色两种位图。因此当指定的设备环境是内存设备环境时,由CreateCompatibleBitmap函数返回的位图格式不一定相同。然而为非内存设备环境创建的兼容位图通常拥有相同的颜色格式,并且使用与指定的设备环境一样的色彩调色板。

   如果程序设置 nWidth 或 nHeight 为 0,CreateCompatibleBitmap 返回 1*1像素,单色位图(a 1- by 1-pixel, monochrome bitmap)的句柄。

   如果一个DIB,即由CreateDIBSection创建的位图,被选入由hdc标识的设备环境,CreateCompatibleBitmap 创建一个DIB对象。

   当不使用位图后,调用DeleteObject 删除对象。

下面是MSDN上的例子:

HDC hDC,                 // Handle to the display device context
    hDCMem;              // Handle to the memory device context
HBITMAP hBitmap;         // Handle to the new bitmap
int iWidth, iHeight;     // Width and height of the bitmap

// Retrieve the handle to a display device context for the client
// area of the window.
hDC = GetDC ( hwnd);

// Create a memory device context compatible with the device.
hDCMem = CreateCompatibleDC ( hDC);

// Retrieve the width and height of window display elements.
iWidth  = GetSystemMetrics ( SM_CXSCREEN) / 10;
iHeight = GetSystemMetrics ( SM_CYSCREEN) / 10;

// Create a bitmap compatible with the device associated with the
// device context.
hBitmap = CreateCompatibleBitmap ( hDC, iWidth, iHeight);

// Insert code to use the bitmap.

// Delete the bitmap object and free all resources associated with it.
DeleteObject ( hBitmap);

// Delete the memory device context and the display device context.
DeleteDC ( hDCMem);
DeleteDC (hDC); 


参考

百度百科:CreateCompatibleBitmap

MSDN: CreateCompatibleBitmap 

 


 

转载于:https://www.cnblogs.com/Lisen/archive/2010/01/20/1652111.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值