• 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 


  • 相关阅读:
    Mvc form提交
    FlexiGrid 使用 全选、自动绑定
    Mysql Insert Or Update语法例子
    orderby与groupby同时使用
    SQLSTATE[HY000] [2002] No such file or directory in
    swoole安装
    关于商城分类查询表结构与数据查询
    查询数据库每张表的信息
    php 正则验证
    PHP代码优化
  • 原文地址:https://www.cnblogs.com/Lisen/p/1652111.html
Copyright © 2020-2023  润新知