一个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. android菜鸟学习笔记16----Android项目打包安装过程(Run as Android Application)

    右击项目名称,Run as Android Appication之后,Android项目打包安装过程: 1.打包生成.apk文件: 1)把源码中的.java文件编译生成.class文件 2)将所有的. ...

  2. Chernoff-Hoeffding inequality -- Chernoff bounds, and some applications

    https://www.cs.utah.edu/~jeffp/teaching/cs5955/L3-Chern-Hoeff.pdf [大数据-通过随机过程降维 ] When dealing with ...

  3. MySql 三大知识点——索引、锁、事务(转)

    1. 索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. 索引的优点:1. 天生排序.2. 快速查找.索引的缺点:1. 占用空间.2. 降低更新表的速度. 注意点:小表使用全表扫描 ...

  4. 使用AXIS2作为Client訪问WebService

    使用AXIS2,能够方便的构建WebService的server端,也能够非常方便的作为Cilent,来訪问别的WebService. 以下依据工作中的经历,整理了一下,作为Cilent訪问WebSe ...

  5. ftl总结

    当前项目前端是用freemarker,是第一次使用这种页面,一般语法不介绍,这里只是记录工作中遇到的问题 ---------2016.6.25-------------- 1.关于ftl字符串的问题 ...

  6. 基于ajax和Form实现的注册

    注册 urls.py from django.contrib import admin from django.urls import path, re_path from app01 import ...

  7. Android Weekly Notes Issue #320

    Android Weekly Issue #320 July 29th, 2018 Android Weekly Issue #320 本期内容包括: Firebase的MLKit; 关于写Andro ...

  8. JAVA- continue与break与return关键字

    continue与break关键字 for(int i=0;i<10;i++){ if(i%2==0){ continue; //跳过当前循环执行下一次循环 } System.out.print ...

  9. SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...

  10. riverbed 流量分析——还是在基于流量做运维

    from:https://www.riverbed.com/sg/digital-performance/index.htmlMaximise Your Digital PerformanceConn ...