SetROP2函数 ——设置前景色与背景色
来源:互联网 发布:电子屏图文信息软件 编辑:程序博客网 时间:2024/06/06 05:34
一个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函数 ——设置前景色与背景色
- 前景色与背景色
- [jtable]设置复选框前景色与背景色
- iOS设置状态栏背景色与前景色
- 设置背景色和前景色
- 文档前景色和背景色设置
- krpano——背景色设置
- 如何设置文字的前景色和背景色
- 设置文字的前景色和背景色
- 控制台程序设置背景色和前景色
- wpf后台设置颜色(背景色,前景色)
- c语言设置控制台背景色和前景色
- Photoshop脚本 > 设置前景色和背景色
- POI操作Excel设置前景色背景色
- 怎么设置dos框的背景色和前景色~
- wpf后台设置颜色(背景色,前景色)
- photoshop 图片裁剪与填充前景色及背景色
- android:为TextView添加样式——下划线,颜色,设置链接样式及前背景色
- 【转】PrintStream 和 PrintWriter的区别
- Anroid 界面边框圆角的实现方式
- 字符,字节,和编码
- page cache ,buffer cache,swap space
- 设计模式-FlyWeight
- SetROP2函数 ——设置前景色与背景色
- linux中Oops信息的调试及栈回溯—Linux人都知道,这是好东西!
- WEB原型设计工具Mockup
- 多玩YY靠屌丝用户突出腾讯重围成功上市
- poj 2029
- 真正优秀的程序员有哪些与众不同之处?
- 使用 windbg 分析 minidump
- jquery始终显示DIV中央
- 整型提升