|
现有多个由线段line汇成的闭合区域,将每个区域使用不同的颜色填充。
//绘制图形
// find the client area
CRect rect;
GetClientRect(rect);
// draw with a thick blue pen
CPen penBlue(PS_SOLID, 2, RGB(0, 0, 255));
CPen* pOldPen = pDC->SelectObject(&penBlue);
int colorIndexR;
int colorIndexG;
int colorIndexB;
CBrush *pOldBrush;
for (unsigned int i = 0;i < m_minClosedArea.size(); i++) //m_minClosedArea集合为多个有线段围成的闭合区域
{
vector<CLine> m_oneClosedArea= m_minClosedArea[i];//闭合区域A
int nSize = (int)m_oneClosedArea.size(); //闭合区域的线段数量(点数量)
CPolyline m_polyline;
CPoint pts[100];
//将闭合区域A中的点存放在pts中
for (unsigned int j=0; j<m_oneClosedArea.size(); j++)
{
Point m_ptStart = m_oneClosedArea[j].getStartPoint();
int x1 = (int)m_ptStart.x;
int y1 = (int)m_ptStart.y;
pts[j].SetPoint(x1,-y1);
}
colorIndexR = (i*50 - 50)%256; //颜色索引
colorIndexG = (i*100 + 100)%256; //颜色索引
colorIndexB = (i*200 - 200)%256; //颜色索引
CBrush brushColor(RGB(colorIndexR,colorIndexG, colorIndexB)); //定义画刷的颜色
pOldBrush = pDC->SelectObject(&brushColor); //将画刷颜色赋予*pDC
pDC->Polygon(pts, nSize); //绘制多边形
pDC->SelectObject(&pOldPen);
pDC->SelectObject(pOldBrush);
} |
|