Graphics Class

Represents drawing functionality provided with Graphics Mill.

Namespace: Aurigma.GraphicsMill.Drawing
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public sealed class Graphics : IDisposable

Remarks

This class allows you to draw lines, curves, and shapes as well as text at the Bitmap or device context (it can be a window, printer, etc). Drawing methods can be divided into two groups: outlining and filling ones. Outlining methods draw an outline and has a Draw prefix. E.g.

Filling methods are drawing filled shapes without outline:

This class also provides a wide functionality for text output. There are a number of overloads of the DrawString() method: draw simple string filled with solid color, draw outlined text, draw multiline text, etc.

You can also draw a image using this class. It can be done with overloads of the DrawImage() method.

Sometimes you need to prevent some parts of the bitmap or the device context to be drawn at (i.e. clip the drawing that is outside of some region). Fortunately the Graphics class have a built-in clipping support. You can specify clipping region through the SetClip() methods, and apply set-theory operations (IntersectClip() and ExcludeClip() methods), reset clipping region (ResetClip()), move it (TranslateClip(Int32, Int32)), etc.

If the Graphics features are not enough for you, you can use a power of Windows GDI. Using the GetDC() method you can get a HDC this graphics represents, and use it in GDI functions.

Note

GDI cannot handle bitmaps with an alpha channel when it draws anything on it. As the high byte of 4-byte color must be zero in GDI, each pixel drawn with GDI becomes transparent. So now, if you try to call any drawing methods for the bitmaps with an alpha channel when using GDI, the UnsupportedPixelFormatException exception will be thrown.

Examples

C#
using (var bitmap = new Bitmap(100, 60, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (Graphics graphics = bitmap.GetGraphics())
    {
        var bluePen = new Pen(RgbColor.Blue, 8);
        graphics.DrawLine(bluePen, 10, 55, 90, 5);

        var redPen = new Pen(RgbColor.Red, 8);
        graphics.DrawLine(redPen, 10, 5, 90, 55);

        bitmap.Save(@"Images\Output\pen.png");
    }
}

Inheritance Hierarchy

System.Object
L Aurigma.GraphicsMill.Drawing.Graphics

Thread Safety

Static members of this type are not safe for multi-threaded operations. Instance members of this type are not safe for multi-threaded operations.

See Also

Reference