紧急——GDI+求封闭曲线的外接矩形 如题,GetBounds求出来的不合要求。想实现的是求出封闭曲线的外接矩形,然后实现左到右、上到下等的渐变。求各位先进赐教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 回复一楼,如一楼图,那是多边形的外接矩形,我要得到的是以这三点生成的封闭曲线ClosedCurve的外切矩形。回复二楼,计算量有点大,另这曲线是GDI+自动生成(DrawClosedCure)的,我不知道他的生成算法。难道GDI+没有现成的函数算法可用吗? 急用,谢谢大家 GetBounds和GetBoundsRect为什么不符合要求?你也说你不知道生成算法了,所以只能依靠这种来接口来实现了,估计楼住没处理好的结果 如一楼图所示,GetBounds生成的rect只是包含了3个控制点,封闭曲线包含的范围有很多是在多边形区域外面的 这才是我要的效果(这个不是我的程序画的)。我的图http://hi.csdn.net/attachment/201011/15/5702112_1289819950FSSM.jpg左边一段溢出,没有参加渐变 GraphicsPath path; PointF points[3]; points[0].X = 100.f; points[0].Y = 100.f; points[1].X = 300.f; points[1].Y = 300.f; points[2].X = 500.f; points[2].Y = 100.f; int count = 3; path.AddClosedCurve(points,count); path.CloseAllFigures(); Graphics g(pDC->m_hDC); g.SetSmoothingMode(SmoothingModeHighQuality); g.DrawPath(&Pen(Color::Red),&path); g.FillPath(&SolidBrush(Color::Gray),&path); [Quote=引用 7 楼 j8daxue 的回复:]g.FillPath(&SolidBrush(Color::Gray),&path);谢谢,但是不是我想要的我要的是得出外切的矩形,然后基于这个矩形做渐变等,或则按高度宽度按比例填充 ,不是只要填充灰色图就好了如图,按getbounds出来的矩形,按高度填充了0%下面还有溢出的大量蓝色填充 GraphicsPath path; PointF points[3]; points[0].X = 50.f; points[0].Y = 50.f; points[1].X = 50.f; points[1].Y = 150.f; points[2].X = 250.f; points[2].Y = 100.f; int count = 3; path.AddClosedCurve(points,count); path.CloseAllFigures(); Graphics g(pDC->m_hDC); g.SetSmoothingMode(SmoothingModeHighQuality); RectF rcf; path.GetBounds(&rcf); g.FillPath(&LinearGradientBrush(rcf,Color::White,Color::Black,0),&path); g.DrawPath(&Pen(Color::Black),&path); 你试过9L的代码没?GDI+的填充会按照路径范围剪裁。GetBounds在某些地方效果很好,但对于这个曲线似乎有误差,MSDN的解释是为了容下外接矩形的pen的键帽 谢谢大家。 getbounds有用。是我错了结贴 一个关于复选框的问题 请教.VC调用OCX接口的问题 VB 怎么实现数据包分2次发送 关于消息的一个问题,我就是想不通. sendmessage传递数据的问题? listctrl显示图标 vc++中访问注册表 紧急问题,使用DrawText()避免了显示汉字出现乱码的现象,但是,当一次显示不完时,如何依次显示剩下的部分.... 你知道扩展名为img是什么文件吗? 超初级问题,在文本中输出回车。 文件锁(文件可以被多个"读"操作打开,但是只能有一个"写"操作),应该用什么api和参数? static控件的背景
回复二楼,计算量有点大,另这曲线是GDI+自动生成(DrawClosedCure)的,我不知道他的生成算法。
难道GDI+没有现成的函数算法可用吗? 急用,谢谢大家
你也说你不知道生成算法了,所以只能依靠这种来接口来实现了,估计楼住没处理好的结果
这才是我要的效果(这个不是我的程序画的)。
我的图http://hi.csdn.net/attachment/201011/15/5702112_1289819950FSSM.jpg左边一段溢出,没有参加渐变
GraphicsPath path;
PointF points[3];
points[0].X = 100.f;
points[0].Y = 100.f; points[1].X = 300.f;
points[1].Y = 300.f; points[2].X = 500.f;
points[2].Y = 100.f;
int count = 3;
path.AddClosedCurve(points,count);
path.CloseAllFigures(); Graphics g(pDC->m_hDC);
g.SetSmoothingMode(SmoothingModeHighQuality);
g.DrawPath(&Pen(Color::Red),&path); g.FillPath(&SolidBrush(Color::Gray),&path);
g.FillPath(&SolidBrush(Color::Gray),&path);
谢谢,但是不是我想要的
我要的是得出外切的矩形,然后基于这个矩形做渐变等,或则按高度宽度按比例填充 ,不是只要填充灰色图就好了
如图,按getbounds出来的矩形,按高度填充了0%下面还有溢出的大量蓝色填充
GraphicsPath path;
PointF points[3];
points[0].X = 50.f;
points[0].Y = 50.f; points[1].X = 50.f;
points[1].Y = 150.f; points[2].X = 250.f;
points[2].Y = 100.f;
int count = 3;
path.AddClosedCurve(points,count);
path.CloseAllFigures(); Graphics g(pDC->m_hDC);
g.SetSmoothingMode(SmoothingModeHighQuality);
RectF rcf;
path.GetBounds(&rcf);
g.FillPath(&LinearGradientBrush(rcf,Color::White,Color::Black,0),&path);
g.DrawPath(&Pen(Color::Black),&path);
GDI+的填充会按照路径范围剪裁。
GetBounds在某些地方效果很好,但对于这个曲线似乎有误差,MSDN的解释是为了容下外接矩形的pen的键帽
结贴