GDI+函数之 Region::Complement

39 篇文章 0 订阅
19 篇文章 0 订阅

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, &region);
}



我对它的一个实际应用:

//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);


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值