SetROP2
一个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
举个例子,你使用R2_NOTXORPEN这种绘画模式,你用红色画笔在黑色背景上画一条直线,显示红色,但你再用这只笔在刚画的直线上重画一遍,就相当于把开始画的红线擦除掉了,划线的地方显示为背景色。
R2_NOT绘画模式同样有在同一个地方画两次相当于什么都没画的功能,不过R2_NOT绘画模式第一次画的时候显示颜色并不是你选定的画笔颜色,而是默认的颜色。
这就是这两种绘画模式的区别
SetROP2的更多相关文章
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- MFC绘图(转载)
http://www.cppblog.com/bestcln/articles/83189.html 1 几何对象的结构和类 为了使用绘图函数,应该先了解绘图所用到的几种表示几何对象的结构和类.这些结 ...
- 孙鑫MFC学习笔记4:MFC画图
1.画线方法 *1.捕获鼠标按下和弹起消息,获取两个点 *2.消息响应,画线 2.在CMainFrame类中的鼠标左键事件得不到响应的原因是CNameView覆盖了CMainFrame 3.注释宏 4 ...
- 第5章 绘图基础_5.1-5.4 GDI绘图
5.1 GDI的原理和结构 (1)提供一种特殊机制彻底隔离应用程序与不同输出设备(eg.显示器或打印机),以便支持 与设备无关的图形. 光栅设备(如显示器.激光打印机):图像是由点构成的矩阵 图形输出 ...
- 英文不好也能快速"记忆" API
英文不好不要紧,把API函数导入打字练习类软件,即是练习打字速度,提高编程效率:也能短时间记忆API. 坚持每天打一遍,约2小时,连续打两周,会对API有很好的记忆,此方法是结合英文学习方法!以下是W ...
- [游戏模版1] MFC最小框架(base function including)
>_<:Here are the template of mini-MFC include: CPen,CBrush,Front,Paint Line and some other gra ...
- [游戏学习24] MFC 各种绘图 字体学习
>_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h #include<afxwin.h> class CMyApp ...
- WIN API 擦除所绘图像
COLORREF circle_color = RGB(0, 105, 255); //获取窗口DC HDC hdc = GetDC(hWnd_); //背景色透明 SetBkMode(hdc, TR ...
- VC++ MFC橡皮筋技术
在MFC下绘制直线,使用橡皮筋技术,可以使直线效果跟随鼠标移动 //OnLButtionDown m_ptOrigin = m_ptEnd = point; //OnMouseMove ...
随机推荐
- 九度OJ 1018:统计同成绩学生人数 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8807 解决:4651 题目描述: 读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入: 测试输入包含若干测试用例,每个测试用例的 ...
- wimdows安装mongodb,开机启动
> d: > cd D:\Program Files\MongoDB\Server\3.0\bin > .\mongod --logpath "D:\Program Fil ...
- Hibernate连接池设置
在公司第一次做项目放到服务器上测试,发现每隔一段时间不用数据库就连接不上了(以前学过连接池,很久没用就忘了),在myeclipse上的时候没发现,网上搜索才发现是hibernate连接池配置问题. 1 ...
- react-navigation遇到的坑
关于goBack返回指定页面 react-navigation是提供了goBack()到指定页面的方法的,那就是在goBack()中添加一个参数,但当你使用goBack('Main')的时候,你会发现 ...
- 将socket通信实现多进程
我们知道,使用TCP协议需要提前建立连接,这样就只能一对一的传输,但是这样感觉十分单一,如果实现一个服务器能同时和多个客户端同信了? 这里就需要用到多线程. 处理的不同之处就在于:每一个接进来的客户都 ...
- Java for LeetCode 101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- leetcode 303. Range Sum Query - Immutable(前缀和)
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- xgboost算法原理
XGBoost是2014年3月陈天奇博士提出的,是基于CART树的一种boosting算法,XGBoost使用CART树有两点原因:对于分类问题,CART树的叶子结点对应的值是一个实际的分数,而非一个 ...
- bjwc Day2 玄学
早晨起来很开心,因为昨天跟妹子聊天聊到很晚 然后看到了题,感觉:这tm才是冬令营呀! T1构造,并没有找到性质,暴力都懒得打 T2数位dp,状态比较麻烦,看来跟dmy想到一起了,然后搞一下搞完 T3放 ...
- [CTSC 2012] Cheat
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2806 [算法] 首先建立广义后缀自动机 注意到问题具有单调性 , 不妨对于每组询问二 ...