Как нарисовать заполненный путь, построенный из дуг - PullRequest
0 голосов
/ 09 июля 2019

Может быть простой вопрос:

как нарисовать заполненный графический контур, построенный из линий и дуг? Проблема в том, что GDI + определяет дугу от начального угла до конечного угла только с ориентацией по часовой стрелке.

Изображение будет сделано

Образец (любой язык) был бы великолепен!

Это должно быть сделано путем установки конечной точки дуги, начальной точки следующей линии и т. Д.

1 Ответ

0 голосов
/ 09 июля 2019

A way =>

  • Результат:

enter image description here

  • Код (C #, VS2015): (рисунок на экране 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);
}
...