C#将线高调整为椭圆 [英] C# make line height adjust to ellipse
问题描述
graphGraphics = e.Graphics;
graphGraphics.FillEllipse(新的SolidBrush(Color.White),this.graphBoundries);
graphGraphics.DrawEllipse(graphPen,this.graphBoundries);
我在这张图上有一条线,它现在正好穿过它。我想改变线的高度以适应椭圆的边界如下,所以它不会通过椭圆:
http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png
有谁知道一个算法来做到这一点?或者,甚至可能是如何获得椭圆的边界而不仅仅是矩形的边界?解析方案
为了扩展我的评论,尝试一下像这样(未经测试)的代码:
graphGraphics = e.Graphics;
graphGraphics.FillEllipse(新的SolidBrush(Color.White),this.graphBoundries);
graphGraphics.DrawEllipse(graphPen,this.graphBoundries);
GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(this.graphBoundaries);
graphGraphics.SetClip(clipPath,CombineMode.Replace);
//画线
There is an ellipse drawn with the following code:
graphGraphics = e.Graphics;
graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);
I have a line on this graph and it currently just passes right through it. I want to change the lines height to adjust to the ellipse's boundaries as follows so it wont pass through the ellipse:
http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png
Does anyone know an algorithm to do this? Or maybe even how to just get the ellipse's boundaries and not just the rectangular boundaries?
To expand on my comment, try something like this (untested) code:
graphGraphics = e.Graphics;
graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);
GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(this.graphBoundaries);
graphGraphics.SetClip(clipPath, CombineMode.Replace);
// draw your line
这篇关于C#将线高调整为椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!