我对GDI有问题。我在WinForms中完成。我得到了:
还有我的代码:
Graphics phantom = this.pictureBox1.CreateGraphics();
Pen blackPen = new Pen(Color.Black, 3);
Rectangle rect = new Rectangle(0, 0, 200, 150);
float startAngle = 180F;
float sweepAngle = 180F;
phantom.DrawArc(blackPen, rect, startAngle, sweepAngle);
phantom.Dispose();
我想得到这样的东西:
非常抱歉,我的绘画技巧。是否可以从圆弧本身创建这样的东西,还是必须从椭圆形创建呢?我不知道该怎么做。欢迎任何提示。谢谢。
摘自我对原始帖子的评论:
您有两个圆圈,我们称其为上下两圈。定义上方的圆作为GraphicsPath并将其传递给区域。现在,通过ExcludeClip方法将该Region传递给e.Graphics。现在画下面的圆圈,该圆圈将缺少顶部,因为剪辑。接下来,对图形进行Reset()并定义下图在GraphicsPath中圈出。这次使用Graphics.Clip()并追逐画上一个圆圈。只有在下部的圆形夹为。
概念证明:
代码:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics phantom = e.Graphics;
using (Pen blackPen = new Pen(Color.Black, 3))
{
Rectangle upper = new Rectangle(-50, -250, 300, 300);
GraphicsPath upperGP = new GraphicsPath();
upperGP.AddEllipse(upper);
using (Region upperRgn = new Region(upperGP))
{
Rectangle lower = new Rectangle(0, 0, 200, 150);
GraphicsPath lowerGP = new GraphicsPath();
lowerGP.AddEllipse(lower);
float startAngle = 180F;
float sweepAngle = 180F;
phantom.ExcludeClip(upperRgn);
phantom.DrawArc(blackPen, lower, startAngle, sweepAngle);
phantom.ResetClip();
phantom.SetClip(lowerGP);
phantom.DrawEllipse(blackPen, upper);
}
}
}