Class Graphics

Graphics class

Represents the graphics according to the graphics engine used in the current assembly.

public sealed class Graphics

Constructors

NameDescription
Graphics(Image)Initializes a new instance of the Graphics class.

Properties

NameDescription
Clip { get; set; }Gets or sets the clip region.
CompositingQuality { get; set; }Gets or sets the compositing quality.
DpiX { get; }Gets the horizontal resolution of this Aspose.Imaging.Graphics.
DpiY { get; }Gets the vertical resolution of this Aspose.Imaging.Graphics.
Image { get; }Gets the image.
InterpolationMode { get; set; }Gets or sets the interpolation mode.
IsInBeginUpdateCall { get; }Gets a value indicating whether graphics is in BeginUpdate call state.
PageScale { get; set; }Gets or sets the scaling between world units and page units for this Aspose.Imaging.Graphics.
PageUnit { get; set; }Gets or sets the unit of measure used for page coordinates in this Aspose.Imaging.Graphics.
PaintableImageOptions { get; set; }Gets or sets image options, used to create paintable vactor images to draw.
SmoothingMode { get; set; }Gets or sets the smoothing mode.
TextRenderingHint { get; set; }Gets or sets the text rendering hint.
Transform { get; set; }Gets or sets a copy of the geometric world transformation for this Graphics.

Methods

NameDescription
BeginUpdate()Starts caching of the following graphics operations. The graphics effects applied afterwards will not be applied immediately instead the EndUpdate will cause applying all the effects at once.
Clear(Color)Clears the graphics surface using the specified color.
DrawArc(Pen, Rectangle, float, float)Draws an arc representing a portion of an ellipse specified by a Rectangle structure.
DrawArc(Pen, RectangleF, float, float)Draws an arc representing a portion of an ellipse specified by a RectangleF structure.
DrawArc(Pen, float, float, float, float, float, float)Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height.
DrawArc(Pen, int, int, int, int, int, int)Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height.
DrawBezier(Pen, Point, Point, Point, Point)Draws a Bézier spline defined by four Point structures.
DrawBezier(Pen, PointF, PointF, PointF, PointF)Draws a Bézier spline defined by four PointF structures.
DrawBezier(Pen, float, float, float, float, float, float, float, float)Draws a Bézier spline defined by four ordered pairs of coordinates that represent points.
DrawBeziers(Pen, PointF[])Draws a series of Bézier splines from an array of PointF structures.
DrawBeziers(Pen, Point[])Draws a series of Bézier splines from an array of Point structures.
DrawClosedCurve(Pen, PointF[])Draws a closed cardinal spline defined by an array of PointF structures. This method uses a default tension of 0.5 and Alternate fill mode.
DrawClosedCurve(Pen, Point[])Draws a closed cardinal spline defined by an array of Point structures. This method uses a default tension of 0.5 and Alternate fill mode.
DrawClosedCurve(Pen, PointF[], float)Draws a closed cardinal spline defined by an array of PointF structures using a specified tension. This method uses a default Alternate fill mode.
DrawClosedCurve(Pen, Point[], float)Draws a closed cardinal spline defined by an array of Point structures using a specified tension. This method uses a default Alternate fill mode.
DrawCurve(Pen, PointF[])Draws a cardinal spline through a specified array of PointF structures. This method uses a default tension of 0.5.
DrawCurve(Pen, Point[])Draws a cardinal spline through a specified array of Point structures.
DrawCurve(Pen, PointF[], float)Draws a cardinal spline through a specified array of PointF structures using a specified tension.
DrawCurve(Pen, Point[], float)Draws a cardinal spline through a specified array of Point structures using a specified tension.
DrawCurve(Pen, PointF[], int, int)Draws a cardinal spline through a specified array of PointF structures. The drawing begins offset from the beginning of the array. This method uses a default tension of 0.5.
DrawCurve(Pen, PointF[], int, int, float)Draws a cardinal spline through a specified array of PointF structures using a specified tension. The drawing begins offset from the beginning of the array.
DrawCurve(Pen, Point[], int, int, float)Draws a cardinal spline through a specified array of Point structures using a specified tension.
DrawEllipse(Pen, Rectangle)Draws an ellipse specified by a bounding Rectangle structure.
DrawEllipse(Pen, RectangleF)Draws an ellipse defined by a bounding RectangleF.
DrawEllipse(Pen, float, float, float, float)Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
DrawEllipse(Pen, int, int, int, int)Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
DrawImage(Image, Point)Draws the specified Image, using its original physical size, at the specified location.
DrawImage(Image, PointF)Draws the specified Image, using its original physical size, at the specified location.
DrawImage(Image, PointF[])Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Point[])Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Rectangle)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, RectangleF)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, float, float)Draws the specified Image, using its original physical size, at the specified location.
DrawImage(Image, int, int)Draws the specified image, using its original physical size, at the location specified by a coordinate pair.
DrawImage(Image, PointF[], RectangleF)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Point[], Rectangle)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Rectangle, GraphicsUnit)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, RectangleF, GraphicsUnit)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, PointF[], RectangleF, GraphicsUnit)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Point[], Rectangle, GraphicsUnit)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Rectangle, GraphicsUnit, ImageAttributes)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, RectangleF, GraphicsUnit, ImageAttributes)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, float, float, float, float)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, int, int, int, int)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)Draws the specified portion of the specified image at the specified location and with the specified size.
DrawImage(Image, Rectangle, Rectangle, GraphicsUnit, ImageAttributes)Draws the specified Image at the specified location and with the specified size.
DrawImage(Image, RectangleF, RectangleF, GraphicsUnit, ImageAttributes)Draws the specified Image at the specified location and with the specified size.
DrawImageUnscaled(Image, Point)Draws a specified image using its original physical size at a specified location.
DrawImageUnscaled(Image, Rectangle)Draws a specified image using its original physical size at a specified location.
DrawImageUnscaled(Image, int, int)Draws the specified image using its original physical size at the location specified by a coordinate pair.
DrawImageUnscaled(Image, int, int, int, int)Draws a specified image using its original physical size at a specified location.
DrawImageUnscaledAndClipped(Image, Rectangle)Draws the specified image without scaling and clips it, if necessary, to fit in the specified rectangle.
DrawLine(Pen, Point, Point)Draws a line connecting two Point structures.
DrawLine(Pen, PointF, PointF)Draws a line connecting two PointF structures.
DrawLine(Pen, float, float, float, float)Draws a line connecting the two points specified by the coordinate pairs.
DrawLine(Pen, int, int, int, int)Draws a line connecting the two points specified by the coordinate pairs.
DrawLines(Pen, PointF[])Draws a series of line segments that connect an array of PointF structures.
DrawLines(Pen, Point[])Draws a series of line segments that connect an array of Point structures.
DrawPath(Pen, GraphicsPath)Draws a GraphicsPath.
DrawPie(Pen, Rectangle, float, float)Draws a pie shape defined by an ellipse specified by a Rectangle structure and two radial lines.
DrawPie(Pen, RectangleF, float, float)Draws a pie shape defined by an ellipse specified by a RectangleF structure and two radial lines.
DrawPie(Pen, float, float, float, float, float, float)Draws a pie shape defined by an ellipse specified by a coordinate pair, a width, a height, and two radial lines.
DrawPie(Pen, int, int, int, int, int, int)Draws a pie shape defined by an ellipse specified by a coordinate pair, a width, a height, and two radial lines.
DrawPolygon(Pen, PointF[])Draws a polygon defined by an array of PointF structures.
DrawPolygon(Pen, Point[])Draws a polygon defined by an array of Point structures.
DrawRectangle(Pen, Rectangle)Draws a rectangle specified by a Rectangle structure.
DrawRectangle(Pen, RectangleF)Draws a rectangle specified by a RectangleF structure.
DrawRectangle(Pen, float, float, float, float)Draws a rectangle specified by a coordinate pair, a width, and a height.
DrawRectangle(Pen, int, int, int, int)Draws a rectangle specified by a coordinate pair, a width, and a height.
DrawRectangles(Pen, RectangleF[])Draws a series of rectangles specified by RectangleF structures.
DrawRectangles(Pen, Rectangle[])Draws a series of rectangles specified by Rectangle structures.
DrawString(string, Font, Brush, PointF)Draws the specified text string at the specified location with the specified Brush and Font objects.
DrawString(string, Font, Brush, RectangleF)Draws the specified text string in the specified rectangle with the specified Brush and Font objects.
DrawString(string, Font, Brush, float, float)Draws the specified text string at the specified location with the specified Brush and Font objects.
DrawString(string, Font, Brush, PointF, StringFormat)Draws the specified text string at the specified location with the specified Brush and Font objects using the formatting attributes of the specified StringFormat.
DrawString(string, Font, Brush, RectangleF, StringFormat)Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat.
DrawString(string, Font, Brush, float, float, StringFormat)Draws the specified text string at the specified location with the specified Brush and Font objects using the formatting attributes of the specified StringFormat.
EndUpdate()Finishes caching of the graphics operations started after BeginUpdate was called. The preceding graphics operations will be applied at once when calling this method.
FillClosedCurve(Brush, PointF[])Fills the interior of a closed cardinal spline curve defined by an array of PointF structures. This method uses a default tension of 0.5 and Alternate fill mode.
FillClosedCurve(Brush, Point[])Fills the interior of a closed cardinal spline curve defined by an array of Point structures. This method uses a default tension of 0.5 and Alternate fill mode.
FillClosedCurve(Brush, PointF[], FillMode)Fills the interior of a closed cardinal spline curve defined by an array of PointF structures using the specified fill mode. This method uses a default tension of 0.5.
FillClosedCurve(Brush, Point[], FillMode)Fills the interior of a closed cardinal spline curve defined by an array of Point structures using the specified fill mode. This method uses a default tension of 0.5.
FillClosedCurve(Brush, PointF[], FillMode, float)Fills the interior of a closed cardinal spline curve defined by an array of PointF structures using the specified fill mode and tension.
FillClosedCurve(Brush, Point[], FillMode, float)Fills the interior of a closed cardinal spline curve defined by an array of Point structures using the specified fill mode and tension.
FillEllipse(Brush, Rectangle)Fills the interior of an ellipse defined by a bounding rectangle specified by a Rectangle structure.
FillEllipse(Brush, RectangleF)Fills the interior of an ellipse defined by a bounding rectangle specified by a RectangleF structure.
FillEllipse(Brush, float, float, float, float)Fills the interior of an ellipse defined by a bounding rectangle specified by a pair of coordinates, a width, and a height.
FillEllipse(Brush, int, int, int, int)Fills the interior of an ellipse defined by a bounding rectangle specified by a pair of coordinates, a width, and a height.
FillPath(Brush, GraphicsPath)Fills the interior of a GraphicsPath.
FillPie(Brush, Rectangle, float, float)Fills the interior of a pie section defined by an ellipse specified by a RectangleF structure and two radial lines.
FillPie(Brush, RectangleF, float, float)Fills the interior of a pie section defined by an ellipse specified by a RectangleF structure and two radial lines.
FillPie(Brush, float, float, float, float, float, float)Fills the interior of a pie section defined by an ellipse specified by a pair of coordinates, a width, a height, and two radial lines.
FillPie(Brush, int, int, int, int, int, int)Fills the interior of a pie section defined by an ellipse specified by a pair of coordinates, a width, a height, and two radial lines.
FillPolygon(Brush, PointF[])Fills the interior of a polygon defined by an array of points specified by PointF structures and Alternate.
FillPolygon(Brush, Point[])Fills the interior of a polygon defined by an array of points specified by Point structures and Alternate.
FillPolygon(Brush, PointF[], FillMode)Fills the interior of a polygon defined by an array of points specified by PointF structures using the specified fill mode.
FillPolygon(Brush, Point[], FillMode)Fills the interior of a polygon defined by an array of points specified by Point structures using the specified fill mode.
FillRectangle(Brush, Rectangle)Fills the interior of a rectangle specified by a Rectangle structure.
FillRectangle(Brush, RectangleF)Fills the interior of a rectangle specified by a RectangleF structure.
FillRectangle(Brush, float, float, float, float)Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.
FillRectangle(Brush, int, int, int, int)Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.
FillRectangles(Brush, RectangleF[])Fills the interiors of a series of rectangles specified by RectangleF structures.
FillRectangles(Brush, Rectangle[])Fills the interiors of a series of rectangles specified by Rectangle structures.
FillRegion(Brush, Region)Fills the interior of a Region.
MeasureString(string, Font, SizeF, StringFormat)Measures the specified text string with specified parameters
MultiplyTransform(Matrix)Multiplies the Matrix that represents the local geometric transform of this Graphics by the specified Matrix by prepending the specified Matrix.
MultiplyTransform(Matrix, MatrixOrder)Multiplies the Matrix that represents the local geometric transform of this Graphics by the specified Matrix in the specified order.
ResetTransform()Resets the Transform property to identity.
RotateTransform(float)Rotates the local geometric transform by the specified amount. This method prepends the rotation to the transform.
RotateTransform(float, MatrixOrder)Rotates the local geometric transform by the specified amount in the specified order.
ScaleTransform(float, float)Scales the local geometric transform by the specified amounts. This method prepends the scaling matrix to the transform.
ScaleTransform(float, float, MatrixOrder)Scales the local geometric transform by the specified amounts in the specified order.
TranslateTransform(float, float)Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.
TranslateTransform(float, float, MatrixOrder)Translates the local geometric transform by the specified dimensions in the specified order.

Examples

This example uses Graphics class to create primitive shapes on the Image surface. To demonstrate the operation, the example creates a new Image in PNG format and draw primitive shapes on Image surface using Draw methods exposed by Graphics class

[C#]

//Creates an instance of FileStream
using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
{
    //Create an instance of PngOptions and set its various properties
    Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();

    //Set the Source for PngOptions
    pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

    //Create an instance of Image 
    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
    {
        //Create and initialize an instance of Graphics class
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

        //Clear Graphics surface
        graphics.Clear(Aspose.Imaging.Color.Wheat);

        //Draw an Arc by specifying the Pen object having Black color, 
        //a Rectangle surrounding the Arc, Start Angle and Sweep Angle
        graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);

        //Draw a Bezier by specifying the Pen object having Blue color and co-ordinate Points.
        graphics.DrawBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Point(250, 100), new Aspose.Imaging.Point(300, 30), new Aspose.Imaging.Point(450, 100), new Aspose.Imaging.Point(235, 25));

        //Draw a Curve by specifying the Pen object having Green color and an array of Points
        graphics.DrawCurve(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new[] { new Aspose.Imaging.Point(100, 200), new Aspose.Imaging.Point(100, 350), new Aspose.Imaging.Point(200, 450) });

        //Draw an Ellipse using the Pen object and a surrounding Rectangle
        graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));

        //Draw a Line 
        graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));

        //Draw a Pie segment
        graphics.DrawPie(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Silver, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(200, 20), new Aspose.Imaging.Size(200, 200)), 0, 45);

        //Draw a Polygon by specifying the Pen object having Red color and an array of Points
        graphics.DrawPolygon(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2), new[] { new Aspose.Imaging.Point(20, 100), new Aspose.Imaging.Point(20, 200), new Aspose.Imaging.Point(220, 20) });

        //Draw a Rectangle
        graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(250, 250), new Aspose.Imaging.Size(100, 100)));

        //Create a SolidBrush object and set its various properties
        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
        brush.Color = Color.Purple;
        brush.Opacity = 100;

        //Draw a String using the SolidBrush object and Font, at specific Point
        graphics.DrawString("This image is created by Aspose.Imaging API", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));

        // save all changes.
        image.Save();
    }
}

See Also