SetROP2

SetROP2是Windows的函式,該函式的主要的作用是根據nDrawMode設定的方式重新設定繪圖的方式。

Windows API SetROP2(int nDrawMode)的使用

函式的主要的作用

根據nDrawMode設定的方式重新設定繪圖的方式,下面就不同的nDrawMode值具體解釋繪圖模式是如何改變的。
首先就nDrawMode的取值有以下的情況:
1、R2_BLACK Pixel is always black. //所有繪製出來的像素為黑色
2、R2_WHITE Pixel is always white. //所有繪製出來的像素為白色
3、R2_NOP Pixel remains unchanged. //任何繪製將不改變當前的狀態
4、R2_NOT Pixel is the inverse of the screen color. //當前繪製的像素值設為螢幕像素值的反,這樣可以覆蓋掉上次的繪圖,(自動擦除上次繪製的圖形)
5、R2_COPYPEN Pixel is the pen color. //使用當前的畫筆的顏色
6、R2_NOTCOPYPEN Pixel is the inverse of the pen color. //當前畫筆的反色
//下面是當前畫筆的顏色和螢幕色的組合運算得到的繪圖模式。
7、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_COPYPEN和R2_NOT的並集
8、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_COPYPEN和R2_NOT的交集
9、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_NOTCOPYPEN和螢幕像素值的並集
10、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_NOTCOPYPEN和螢幕像素值的交集
11、R2_MERGEPEN Pixel is a combination of the pen color and the screen color (final pixel = pen OR screen pixel). //R2_COPYPEN和螢幕像素值的並集
12、R2_NOTMERGEPEN Pixel is the inverse of the R2_MERGEPEN color (final pixel = NOT(pen OR screen pixel)). //R2_MERGEPEN的反色
13、R2_MASKPEN Pixel is a combination of the colors common to both the pen and the screen (final pixel = pen AND screen pixel). //R2_COPYPEN和螢幕像素值的交集
14、R2_NOTMASKPEN Pixel is the inverse of the R2_MASKPEN color (final pixel = NOT(pen AND screen pixel)). //R2_MASKPEN的反色
15、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_COPYPEN和螢幕像素值的異或
16、R2_NOTXORPEN Pixel is the inverse of the R2_XORPEN color (final pixel = NOT(pen XOR screen pixel)). //R2_XORPEN的反色
總之,上述api的一個作用是在需要改變繪圖的模式時,不需要重新設定畫筆,只需要設定不同的繪圖的模式即可達到相應的目的。

程式橡皮筋繪圖程式的使用實例:

void CXXXView::OnMouseMove(UINT nFlags, CPoint point)
{
// 按下左鍵移動開始畫圖
if (nFlags == MK_LBUTTON)
{
// 創建畫筆RGB(0x00, 0x00, 0xFF)
HPEN hPen = ::CreatePen(PS_SOLID, m_PenWidth, RGB(0x00, 0x00, 0xFF));
// 使用畫筆
::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);
}
}

相關詞條

熱門詞條

聯絡我們