# 关于多边形填充的问题

yichaozhang 2008-04-07 11:34:26

void DrawTriangle(CDC *pDC,float x0,float y0,int flag,COLORREF cr,int dis,int nWidth,int nPenStyle)//
{

float x1,y1,x2,y2;
x1=x0+dis*(0.866)*(flag);
y1=y0-dis/2;
x2=x0+dis*(0.866)*(flag);
y2=y0+dis/2;

CPoint p[2];
p[0].x=x0;
p[0].y=y0;

p[1].x=x1;
p[1].y=y1;

p[2].x=x2;
p[2].y=y2;

CRgn rgnA;
rgnA.CreatePolygonRgn( p, 3, ALTERNATE );
CBrush brA;
brA.CreateSolidBrush( RGB(255, 0, 0) );
pDC->SelectObject(&brA);
pDC->FillRgn( &rgnA, &brA );

}

void DrawTriangle(CDC *pDC,float x0,float y0,int flag,COLORREF cr,int dis,int nWidth,int nPenStyle)//
{

CPen *pNewPen=new CPen;
pNewPen->CreatePen (nPenStyle,0,cr);
CPen *pOldPen=pDC->SelectObject (pNewPen);
float x1,y1,x2,y2;
x1=x0+dis*(0.866)*(flag);
y1=y0-dis/2;
x2=x0+dis*(0.866)*(flag);
y2=y0+dis/2;
pDC->MoveTo(x0,y0);
pDC->LineTo(x1,y1);
pDC->LineTo(x2,y2);
pDC->LineTo(x0,y0);
pDC->SelectObject (pOldPen);
delete pNewPen;

} 注 （x0,y0)(x1,y1),(x2,y2)为定点坐标

...全文
70 3 打赏 收藏 举报

3 条回复

yichaozhang 2008-04-08
• 打赏
• 举报

• 打赏
• 举报

CPoint p[3];
scq2099yt 2008-04-08
• 打赏
• 举报

GDI+
CPoint p[3];

1.9w+

VC/MFC 图形处理/算法

2008-04-07 11:34