Bitmap.GetGraphics Method

Gets the Graphics object associated with this Bitmap.

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

Syntax

C#
public Graphics GetGraphics()

Return Value

A Graphics object associated with this Bitmap.

Remarks

Several calls of this method will return the same object.

You can freely dispose the Graphics returned with this method, although it is not necessary. If you dispose this graphics object, next call of the GetGraphics() method will create new instance of this class.

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");
    }
}

See Also

Reference