This documentation is for the old version. Go to the latest Graphics Mill docs

Drawing Lines and Curves

At this article we will see a code example showing how to draw lines and curves in Graphics Mill for .NET.

Drawing functionality of Graphics Mill for .NET is presented by GdiGraphics class. To draw lines, you should use DrawLine and DrawLines methods of this class. Here you pass coordinates of one or several lines.

Curves can be drawn with DrawBezier and DrawBeziers. These method draws one or several Bezier splines. Each Bezier spline is described by four points - start, end, and two control points which describe the tangent of the curve. When several splines are drawn, end point of the spline is used as a starting point of the next spline.

Another kind of curves you can draw is an arc. Arcs may be drawn with DrawArc. Here you specify an ellipse and a sector on this ellipse to draw.

The appearance of the lines and curves is managed by special object called pen. You can read about it in more details in the Pens and Brushes article.

The code below demonstrates the usage of these methods. This figure demonstrates the output of this code.

GDI graphics
Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 185, 145, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics()

'Draw line
Dim pen As New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Red, 5)
graphics.DrawLine(pen, 10, 10, 100, 60)

'Draw polyline
pen.Color = Aurigma.GraphicsMill.RgbColor.FromArgb(150, 0, 255, 0)
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
pen.Width = 2
Dim points1 As System.Drawing.Point() = { _
 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 = Aurigma.GraphicsMill.RgbColor.Blue
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid
Dim points2 As System.Drawing.Point() = { _
 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)
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 185, 145, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

//Draw line
Aurigma.GraphicsMill.Drawing.Pen pen = new Aurigma.GraphicsMill.Drawing.Pen(
    Aurigma.GraphicsMill.RgbColor.Red, 5);
graphics.DrawLine(pen, 10, 10, 100, 60);

//Draw polyline
pen.Color = Aurigma.GraphicsMill.RgbColor.FromArgb(150, 0, 255, 0);
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 = Aurigma.GraphicsMill.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);

Pay attention, these method work in the same way as the corresponding methods of the System.Drawing.Graphics class. The code example for System.Drawing.Graphics usage can be found below. However before using it, we would recommend you read an article Comparison: GdiGraphics and System.Drawing.Graphics.

The output of this code is adduced here:

GDI+ graphics
Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 185, 145, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As System.Drawing.Graphics = bitmap.GetGdiplusGraphics()

graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias

'Draw line
Dim pen As 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.Green)
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
pen.Width = 2
Dim points1 As System.Drawing.Point() = { _
 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
Dim points2 As System.Drawing.Point() = { _
 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)
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 185, 145,
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

System.Drawing.Graphics graphics = bitmap.GetGdiplusGraphics();

graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

//Draw line
System.Drawing.Pen 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.Green);
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);