Drawing Lines and Curves

Warning

Drawing functionality described in this topic is out of date. If you want to learn how to draw lines and curves using the new drawing engine in Graphics Mill, read the Graphics. Drawing Images and Geometric Shapes article.

The article describes how to draw lines and curves in Graphics Mill. Drawing functionality in Graphics Mill is presented by the Graphics class, which supports the drawing of the following line types:

  • Lines. Use the DrawLine method to draw lines.
  • Polylines are continuous lines composed of one or more line segments. The DrawLines method allows the drawing of polylines. The method presumes that the end point of a line is the start point of the next line.
  • Bezier curves are parametric curves. To draw a Bezier curve use the DrawBezier method, or the DrawBeziers method to create a sequence of connected curves. Each curve is described by four points: two control points, start point, and end point. The control points describe the tangent of the curve. The DrawBeziers method presumes that the end point of a spline is the start point of the next spline.
  • Arcs are another kind of curve. To draw an arc utilize the DrawArc method. The method accepts ellipse bounding rectangle, start angle, and sweep angle as arguments.

To manage lines and curves appearance use a Pen class instance. For more information see the Pens and Brushes topic.

The following code draws a line, a polyline, and a Bezier curve as shown in the image:

GDI graphics

C#
using (var bitmap = new Bitmap(185, 145, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (Graphics graphics = bitmap.GetGraphics())
    {
        //Draw line
        var pen = new Pen(RgbColor.Red, 5);
        graphics.DrawLine(pen, 10, 10, 100, 60);

        //Draw polyline
        pen.Color = RgbColor.LawnGreen;
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        pen.Width = 2;
        System.Drawing.Point[] points1 = { 
            new System.Drawing.Point(20, 30), new System.Drawing.Point(50, 2), 
            new System.Drawing.Point(180, 30), new System.Drawing.Point(80, 140)
        };
        graphics.DrawLines(pen, points1);

        //Draw beizer
        pen.Color = RgbColor.Blue;
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        System.Drawing.Point[] points2 = { 
            new System.Drawing.Point(5, 5), new System.Drawing.Point(20, 150), 
            new System.Drawing.Point(165, 80), new System.Drawing.Point(175, 10)
        };
        graphics.DrawBeziers(pen, points2);
    }
    bitmap.Save(@"Images\Output\lines.png");
}

You might notice that methods described above are similar to methods of the System.Drawing.Graphics class. If you rewrite the previous code in order to use the System.Drawing.Graphics class, instead of Aurigma.GraphicsMill.Drawing.Graphics, and the method calls remain untouched, the result will be as follows:

GDI+ graphics

C#
using (var bitmap = new Bitmap(185, 145, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (System.Drawing.Graphics graphics = bitmap.GetGdiPlusGraphics())
    {
        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

        //Draw line
        var pen = new System.Drawing.Pen(System.Drawing.Color.Red, 5);
        graphics.DrawLine(pen, 10, 10, 100, 60);

        //Draw polyline
        pen.Color = System.Drawing.Color.FromArgb(150, System.Drawing.Color.LawnGreen);
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        pen.Width = 2;
        System.Drawing.Point[] points1 = { 
            new System.Drawing.Point(20, 30), new System.Drawing.Point(50, 2), 
            new System.Drawing.Point(180, 30), new System.Drawing.Point(80, 140)
        };
        graphics.DrawLines(pen, points1);

        //Draw beizer
        pen.Color = System.Drawing.Color.Blue;
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        System.Drawing.Point[] points2 = {
            new System.Drawing.Point(5, 5), new System.Drawing.Point(20, 150), 
            new System.Drawing.Point(165, 80), new System.Drawing.Point(175, 10)
        };
        graphics.DrawBeziers(pen, points2);
    }
    bitmap.Save(@"Images\Output\lines.png");
}
Note

Each class, Aurigma.GraphicsMill.Drawing.Graphics and System.Drawing.Graphics, have their own highs and lows. We recommend that you read the AdvancedDrawing.Graphics vs Drawing.Graphics vs System.Drawing.Graphics topic before making a decision on which class to use.

See Also

Reference

Manual