【问题标题】:C# make line height adjust to ellipseC#使行高调整为椭圆
【发布时间】:2015-01-14 21:28:04
【问题描述】:

有一个椭圆用以下代码绘制:

graphGraphics = e.Graphics;

graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);

我在这张图上有一条线,它目前正好穿过它。我想改变线条高度以适应椭圆的边界,如下所示,这样它就不会穿过椭圆:

http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png

有人知道这样做的算法吗?或者甚至如何获得椭圆的边界而不仅仅是矩形边界?

【问题讨论】:

标签: c# graphics line ellipse


【解决方案1】:

要扩展我的评论,请尝试以下代码(未经测试):

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

【讨论】:

  • 您好,感谢您的回复。但是,我似乎没有 GraphicsPath。我也已经有了“使用 System.Drawing;”在顶部声明。任何想法如何将其添加到我的项目中?谢谢。
  • 是的,它在 System.Drawing.Drawing2D 中。希望这会有所帮助。
  • 啊,谢谢。那行得通。我认为 System.Drawing 可能包含了它,但我也必须添加 System.Drawing.Drawing2D。谢谢 :)。现在测试代码会让你知道。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-02
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
相关资源
最近更新 更多