一个Windows API SetROP2(int nDrawMode)的使用

该函数的主要的作用是根据nDrawMode设置的方式重新设定绘图的方式,下面就不同的nDrawMode值具体解释绘图模式是如何改变的。

首先就nDrawMode的取值有以下的情况:

R2_BLACK Pixel is always black. //所有绘制出来的像素为黑色

R2_WHITE Pixel is always white. //所有绘制出来的像素为白色

R2_NOP Pixel remains unchanged. //任何绘制将不改变当前的状态

R2_NOT Pixel is the inverse of the screen color. //当前绘制的像素值设为屏幕像素值的反,这样可以覆盖掉上次的绘图,(自动擦除上次绘制的图形)

R2_COPYPEN Pixel is the pen color. //使用当前的画笔的颜色

R2_NOTCOPYPEN Pixel is the inverse of the pen color. //当前画笔的反色

//下面是当前画笔的颜色和屏幕色的组合运算得到的绘图模式。

R2_MERGEPENNOT Pixel is a combination of the pen color and the inverse of the screen color (final pixel = (NOT screen pixel) OR pen).

R2_MASKPENNOT Pixel is a combination of the colors common to both the pen and the inverse of the screen (final pixel = (NOT screen pixel) AND pen).

R2_MERGENOTPEN Pixel is a combination of the screen color and the inverse of the pen color (final pixel = (NOT pen) OR screen pixel).

R2_MASKNOTPEN Pixel is a combination of the colors common to both the screen and the inverse of the pen (final pixel = (NOT pen) AND screen pixel).

R2_MERGEPEN Pixel is a combination of the pen color and the screen color (final pixel = pen OR screen pixel).

R2_NOTMERGEPEN Pixel is the inverse of the R2_MERGEPEN color (final pixel = NOT(pen OR screen pixel)).

R2_MASKPEN Pixel is a combination of the colors common to both the pen and the screen (final pixel = pen AND screen pixel).

R2_NOTMASKPEN Pixel is the inverse of the R2_MASKPEN color (final pixel = NOT(pen AND screen pixel)).

R2_XORPEN Pixel is a combination of the colors that are in the pen or in the screen, but not in both (final pixel = pen XOR screen pixel).

R2_NOTXORPEN Pixel is the inverse of the R2_XORPEN color (final pixel = NOT(pen XOR screen pixel)).

总之,上述api的一个作用是在需要改变绘图的模式时,不需要重新设置画笔,只需要设置不同的绘图的模式即可达到相应的目的。

程序橡皮筋绘图程序的使用实例:

void CXXXView::OnMouseMove(UINT nFlags, CPoint point)

{

// 按下左键移动开始画图

if (nFlags == MK_LBUTTON)

{

// 创建画笔RGB(0x00, 0x00, 0xFF)

HPEN hPen = CreatePen(PS_SOLID, m_PenWidth, m_PenColor);

// 选进DC

::SelectObject(m_hMemDC, hPen);

//设置系统色彩模式取反色

int oldRop=::SetROP2(m_hMemDC,R2_NOTXORPEN);

// 画线

::MoveToEx(m_hMemDC,m_pOrigin.x,m_pOrigin.y, NULL);

::LineTo(m_hMemDC, m_pPrev.x,m_pPrev.y);

//::SetROP2(m_hMemDC,oldRop);//回复系统默认色彩模式

::MoveToEx(m_hMemDC, m_pOrigin.x, m_pOrigin.y, NULL);

::LineTo(m_hMemDC, point.x, point.y);

m_pPrev = point;

Invalidate(FALSE);

}

}

R2_NOTXORPEN

SetROP2 就是设置绘画的模式,绘画模式有很多种,比如最简单的绘画模式就是你的当前画笔是什么颜色,在屏幕上画的就是什么颜色,R2_NOTXORPEN这种绘画 模式是这样的,它先把画笔颜色与屏幕颜色异或,(这里异或是数学计算,1与1为0,1与0为1,我们说颜色其实就是二进制数,)异或之后再取反最后得到一 个颜色值显示在屏幕上。
举个例子,你使用R2_NOTXORPEN这种绘画模式,你用红色画笔在黑色背景上画一条直线,显示红色,但你再用这只笔在刚画的直线上重画一遍,就相当于把开始画的红线擦除掉了,划线的地方显示为背景色。
R2_NOT绘画模式同样有在同一个地方画两次相当于什么都没画的功能,不过R2_NOT绘画模式第一次画的时候显示颜色并不是你选定的画笔颜色,而是默认的颜色。
这就是这两种绘画模式的区别

SetROP2的更多相关文章

  1. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  2. MFC绘图(转载)

    http://www.cppblog.com/bestcln/articles/83189.html 1 几何对象的结构和类 为了使用绘图函数,应该先了解绘图所用到的几种表示几何对象的结构和类.这些结 ...

  3. 孙鑫MFC学习笔记4:MFC画图

    1.画线方法 *1.捕获鼠标按下和弹起消息,获取两个点 *2.消息响应,画线 2.在CMainFrame类中的鼠标左键事件得不到响应的原因是CNameView覆盖了CMainFrame 3.注释宏 4 ...

  4. 第5章 绘图基础_5.1-5.4 GDI绘图

    5.1 GDI的原理和结构 (1)提供一种特殊机制彻底隔离应用程序与不同输出设备(eg.显示器或打印机),以便支持 与设备无关的图形. 光栅设备(如显示器.激光打印机):图像是由点构成的矩阵 图形输出 ...

  5. 英文不好也能快速"记忆" API

    英文不好不要紧,把API函数导入打字练习类软件,即是练习打字速度,提高编程效率:也能短时间记忆API. 坚持每天打一遍,约2小时,连续打两周,会对API有很好的记忆,此方法是结合英文学习方法!以下是W ...

  6. [游戏模版1] MFC最小框架(base function including)

    >_<:Here are the template of mini-MFC include: CPen,CBrush,Front,Paint Line and some other gra ...

  7. [游戏学习24] MFC 各种绘图 字体学习

    >_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h #include<afxwin.h> class CMyApp ...

  8. WIN API 擦除所绘图像

    COLORREF circle_color = RGB(0, 105, 255); //获取窗口DC HDC hdc = GetDC(hWnd_); //背景色透明 SetBkMode(hdc, TR ...

  9. VC++ MFC橡皮筋技术

    在MFC下绘制直线,使用橡皮筋技术,可以使直线效果跟随鼠标移动 //OnLButtionDown        m_ptOrigin = m_ptEnd = point;  //OnMouseMove ...

随机推荐

  1. 最近两周我们接触到的两种线上抓娃娃机的技术实现方案(一种RTSP/一种RTMP)

    线上抓娃娃机需求 最近线上抓娃娃机的项目火爆了,陆陆续续几十款线上抓娃娃机上架,还有一大波正在开发上线中,各大视频云提供商都在蹭热度发布自己的线上抓娃娃机方案,综合了一下,目前线上抓娃娃机的视频需求无 ...

  2. 修改linux的hostname (修改linux系统的IP和hostname)

    # vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=yourname //在这修改hostnameNISDOMAIN=eng-cn.platform.c ...

  3. django使用自己的setting的方法

    创建一个自己的setting xxx.setting export DJANGO_SETTINGS_MODULE="xxx.setting" 然后在项目中import原生的sett ...

  4. 去ioe

    http://baike.baidu.com/link?url=ntILcQyM_S7rpsbUrVu7vLEKHXNfSlJyWdWQnUo9LYO7JfoOpDEvbKldXobL0_nUEkXn ...

  5. JavaScript 如何创建search字段

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. abap 打开文件对话框

    [转自 http://blog.csdn.net/zhongguomao/article/details/6712576] *----------------------- Method 1 ---- ...

  7. Java for LeetCode 123 Best Time to Buy and Sell Stock III【HARD】

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. Java for LeetCode 110 Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  9. CSS3定时提示动画特效

    在线演示 本地下载

  10. BZOJ 3624 [Apio2008]免费道路:并查集 + 生成树 + 贪心【恰有k条特殊路径】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3624 题意: 给你一个无向图,n个点,m条边. 有两种边,种类分别用0和1表示. 让你求一 ...