【问题标题】:How to draw a filled path built of arcs如何绘制由弧线构成的填充路径
【发布时间】:2019-11-18 15:27:09
【问题描述】:

可能是一个简单的问题:

如何绘制由直线和圆弧构成的填充图形路径?问题是,GDI+ 仅以顺时针方向定义了从起始角度到结束角度的弧线。

Image to be made

一个样本(任何语言)都会很棒!

设置圆弧的终点为下一行的起点,以此类推。

【问题讨论】:

    标签: gdi+


    【解决方案1】:

    一种方式 =>

    • 结果:

    • 代码(C#,VS 2015): (在屏幕 DC 上绘图进行测试):
    using (Graphics gr = Graphics.FromHwnd(IntPtr.Zero))
    {
       RectangleF rect = new Rectangle(500, 100, 400, 400 / 2);
       RectangleF rectArc;
       float nXradius = 60;
       float nYradius = 60;
    
       PointF point1, point2;
       GraphicsPath gp = new GraphicsPath();
    
       // Upper Left
       rectArc = new RectangleF(rect.X, rect.Y, 2 * nXradius, 2 * nYradius);
       gp.AddArc(rectArc, 180, 90);
       point1 = new PointF(rect.X + nXradius, rect.Y);                   
    
       // Top Border                   
       point2 = new PointF(rect.Right - nXradius, rect.Y);                   
       gp.AddLine(point1, point2);
    
       // Upper Right.
       rectArc = new RectangleF(rect.Right - 2 * nXradius, rect.Y, 2 * nXradius, 2 * nYradius);
       gp.AddArc(rectArc, 270, 90);
       point1 = new PointF(rect.Right, rect.Y + nYradius);
    
       // Right Border
       point2 = new PointF(rect.Right, rect.Bottom - nYradius);                   
       gp.AddLine(point1, point2);
    
       // Lower Right
       rectArc = new RectangleF(rect.Right, rect.Bottom - 2 * nYradius, 2 * nXradius, 2 * nYradius);
       gp.AddArc(rectArc, -180, -90);
       point1 = new PointF(rect.Right + nXradius, rect.Bottom);
    
       // Bottom Border                  
       point2 = new PointF(rect.X - nXradius, rect.Bottom);                  
       gp.AddLine(point1, point2);
    
       // Lower Left
       rectArc = new RectangleF(rect.X - 2 * nXradius, rect.Bottom - 2 * nYradius, 2 * nXradius, 2 * nYradius);
       gp.AddArc(rectArc, 90, -90);
       point1 = new PointF(rect.X, rect.Bottom - nYradius);                  
    
       // Left Border
       point2 = new PointF(rect.X, rect.Y + nYradius);                   
       gp.AddLine(point1, point2);
    
       gp.CloseFigure();
       System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 10);
       pen.LineJoin = LineJoin.Round;
       gr.SmoothingMode = SmoothingMode.AntiAlias;
       gr.DrawPath(pen, gp);
       gr.FillPath(System.Drawing.Brushes.Orange, gp);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多