TheComplement method updates this region to the portion of the specifiedpath's interior that does not intersect this region.
这个函数用来更新当前Region
用path包含的、同时不在当前区域内的区域(即path区域减去开始region)来更新当前区域。
Msdn的例子比较明白:
代码:
{ Graphics graphics(hdc); SolidBrush solidBrush(Color(255, 255, 0, 0)); Pen pen(Color(255,0,255,0)); Point points[] = { Point(110, 20), Point(120, 30), Point(100, 60), Point(120, 70), Point(150, 60), Point(140, 10)}; Rect rect(65, 15, 70, 45); graphics.DrawRectangle(&pen,rect); GraphicsPath path; path.AddClosedCurve(points, 6); graphics.DrawPath(&pen,&path); // Create a region from a rectangle. Region region(rect); // Update the region so that it consists of all points inside a path but // outside the rectangular region. region.Complement(&path); graphics.FillRegion(&solidBrush, ®ion); }
我对它的一个实际应用:
//ptCircleCenter - 扇形的圆心 //nRadius - 半径 //fAngleStart - 开始的角度 //fSweepAngle - 扇形的总角度 //rgnPie - 得到的区域 void CtestGDIView::GetPieRgnGdiplus(CDC* pDC,CPoint ptCircleCenter,int nRadius,float fAngleStart,float fSweepAngle,__out Region&rgnPie) { //第一步,计算矩形 POINT topLeft; topLeft.x = (LONG)(ptCircleCenter.x-nRadius); topLeft.y = (LONG)(ptCircleCenter.y-nRadius); Rect rectPie(topLeft.x,topLeft.y,nRadius,nRadius); Graphics graphics(pDC->GetSafeHdc()); Pen pen(Color(255,255,0,0)); graphics.DrawRectangle(&pen,rectPie); GraphicsPath path; path.AddPie(rectPie,fAngleStart,fSweepAngle); rgnPie.Complement(&path); }
调用:
Rect rect1(0,0,0,0); Region rgn(rect1); CPoint point(200,200); GetPieRgnGdiplus(pDC,point,100,-90,360,rgn); SolidBrush brush(Color(255,255,0,0)); graphics.FillRegion(&brush,&rgn);
Rect rect1(0,0,0,0); Region rgn(rect1); CPoint point(200,200); GetPieRgnGdiplus(pDC,point,100,-90,-90,rgn); SolidBrush brush(Color(255,255,0,0)); graphics.FillRegion(&brush,&rgn);