设为首页 加入收藏

TOP

在窗口中绘制设备相关位图,图标,设备无关位图
2014-11-23 20:10:21 来源: 作者: 【 】 浏览:10
Tags:口中 绘制 设备 相关 位图 图标 无关

Windows中可以将预先准备好的图像复制到显示区域中,这种内存拷贝执行起来是非常快的。在Windows中提供了两种使用图形拷贝的方法:通过设备相关位图(DDB)和设备无关位图(DIB)。

DDB可以用MFC中的CBitmap来表示,而DDB一般是存储在资源文件中,在加载时只需要通过资源ID号就可以将图形装入。BOOL CBitmap::LoadBitmap( UINT nIDResource )可以装入指定DDB,但是在绘制时必须借助另一个和当前绘图DC兼容的内存DC来进行。通过CDC::BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop )绘制图形,同时指定光栅操作的类型。BitBlt可以将源DC中位图复制到目的DC中,其中前四个参数为目的区域的坐标,接下来是源DC指针,然后是源DC中的起始坐标,由于BitBlt为等比例复制,所以不需要再次指定长宽,(StretchBlt可以进行缩放)最后一个参数为光栅操作的类型,可取以下值:

  • BLACKNESS 输出区域为黑色 Turns all output black.
  • DSTINVERT 反色输出区域 Inverts the destination bitmap.
  • MERGECOPY 在源和目的间使用AND操作 Combines the pattern and the source bitmap using the Boolean AND operator.
  • MERGEPAINT 在反色后的目的和源间使用OR操作 Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.
  • NOTSRCCOPY 将反色后的源拷贝到目的区 Copies the inverted source bitmap to the destination.
  • PATINVERT 源和目的间进行XOR操作 Combines the destination bitmap with the pattern using the Boolean XOR operator.
  • SRCAND 源和目的间进行AND操作 Combines pixels of the destination and source bitmaps using the Boolean AND operator.
  • SRCCOPY 复制源到目的区 Copies the source bitmap to the destination bitmap.
  • SRCINVERT 源和目的间进行XOR操作 Combines pixels of the destination and source bitmaps using the Boolean XOR operator.
  • SRCPAINT 源和目的间进行OR操作 Combines pixels of the destination and source bitmaps using the Boolean OR operator.
  • WHITENESS 输出区域为白色 Turns all output white.

下面用代码演示这种方法:

CYourView::OnDraw(CDC* pDC)
    
{
    
         CDC memDC;//定义一个兼容DC
    
         memDC.CreateCompatibleDC(pDC);//创建DC
    
         CBitmap bmpDraw;
    
         bmpD						
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇利用WinInet开发Internet程序 下一篇为什么需要多进程/线程

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: