Graphics Class
Represents the graphics according to the graphics engine used in the current assembly.
Inheritance Hierarchy
SystemObject
  Aspose.ImagingGraphics

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 20.05
Syntax
public sealed class Graphics

The Graphics type exposes the following members.

Constructors
  NameDescription
Public methodGraphics
Initializes a new instance of the Graphics class.
Properties
  NameDescription
Public propertyClip
Gets or sets the clip region.
Public propertyCompositingQuality
Gets or sets the compositing quality.
Public propertyDpiX
Gets the horizontal resolution of this Aspose.Imaging.Graphics.
Public propertyDpiY
Gets the vertical resolution of this Aspose.Imaging.Graphics.
Public propertyImage
Gets the image.
Public propertyInterpolationMode
Gets or sets the interpolation mode.
Public propertyIsInBeginUpdateCall
Gets a value indicating whether graphics is in BeginUpdate call state.
Public propertyPageScale
Gets or sets the scaling between world units and page units for this Aspose.Imaging.Graphics.
Public propertyPageUnit
Gets or sets the unit of measure used for page coordinates in this Aspose.Imaging.Graphics.
Public propertySmoothingMode
Gets or sets the smoothing mode.
Public propertyTextRenderingHint
Gets or sets the text rendering hint.
Public propertyTransform
Gets or sets a copy of the geometric world transformation for this Graphics.
Methods
  NameDescription
Public methodBeginUpdate
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.
Public methodCode exampleClear
Clears the graphics surface using the specified color.
Public methodCode exampleDrawArc(Pen, Rectangle, Single, Single)
Draws an arc representing a portion of an ellipse specified by a Rectangle structure.
Public methodDrawArc(Pen, RectangleF, Single, Single)
Draws an arc representing a portion of an ellipse specified by a RectangleF structure.
Public methodDrawArc(Pen, Int32, Int32, Int32, Int32, Int32, Int32)
Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height.
Public methodDrawArc(Pen, Single, Single, Single, Single, Single, Single)
Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height.
Public methodCode exampleDrawBezier(Pen, Point, Point, Point, Point)
Draws a Bézier spline defined by four Point structures.
Public methodDrawBezier(Pen, PointF, PointF, PointF, PointF)
Draws a Bézier spline defined by four PointF structures.
Public methodDrawBezier(Pen, Single, Single, Single, Single, Single, Single, Single, Single)
Draws a Bézier spline defined by four ordered pairs of coordinates that represent points.
Public methodDrawBeziers(Pen, Point)
Draws a series of Bézier splines from an array of Point structures.
Public methodDrawBeziers(Pen, PointF)
Draws a series of Bézier splines from an array of PointF structures.
Public methodDrawClosedCurve(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.
Public methodDrawClosedCurve(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.
Public methodDrawClosedCurve(Pen, Point, Single)
Draws a closed cardinal spline defined by an array of Point structures using a specified tension. This method uses a default Alternate fill mode.
Public methodDrawClosedCurve(Pen, PointF, Single)
Draws a closed cardinal spline defined by an array of PointF structures using a specified tension. This method uses a default Alternate fill mode.
Public methodCode exampleDrawCurve(Pen, Point)
Draws a cardinal spline through a specified array of Point structures.
Public methodDrawCurve(Pen, PointF)
Draws a cardinal spline through a specified array of PointF structures. This method uses a default tension of 0.5.
Public methodDrawCurve(Pen, Point, Single)
Draws a cardinal spline through a specified array of Point structures using a specified tension.
Public methodDrawCurve(Pen, PointF, Single)
Draws a cardinal spline through a specified array of PointF structures using a specified tension.
Public methodDrawCurve(Pen, PointF, Int32, Int32)
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.
Public methodDrawCurve(Pen, Point, Int32, Int32, Single)
Draws a cardinal spline through a specified array of Point structures using a specified tension.
Public methodDrawCurve(Pen, PointF, Int32, Int32, Single)
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.
Public methodCode exampleDrawEllipse(Pen, Rectangle)
Draws an ellipse specified by a bounding Rectangle structure.
Public methodDrawEllipse(Pen, RectangleF)
Draws an ellipse defined by a bounding RectangleF.
Public methodDrawEllipse(Pen, Int32, Int32, Int32, Int32)
Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
Public methodDrawEllipse(Pen, Single, Single, Single, Single)
Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width.
Public methodDrawImage(Image, Point)
Draws the specified Image, using its original physical size, at the specified location.
Public methodDrawImage(Image, Point)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, PointF)
Draws the specified Image, using its original physical size, at the specified location.
Public methodDrawImage(Image, PointF)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, Rectangle)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, RectangleF)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Point, Rectangle)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, PointF, RectangleF)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, Rectangle, GraphicsUnit)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, RectangleF, GraphicsUnit)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Int32, Int32)
Draws the specified image, using its original physical size, at the location specified by a coordinate pair.
Public methodDrawImage(Image, Single, Single)
Draws the specified Image, using its original physical size, at the specified location.
Public methodDrawImage(Image, Point, Rectangle, GraphicsUnit)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, PointF, RectangleF, GraphicsUnit)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, Rectangle, GraphicsUnit, ImageAttributes)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Rectangle, Rectangle, GraphicsUnit)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, RectangleF, GraphicsUnit, ImageAttributes)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, RectangleF, RectangleF, GraphicsUnit)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Point, Rectangle, GraphicsUnit, ImageAttributes)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, PointF, RectangleF, GraphicsUnit, ImageAttributes)
Draws the specified portion of the specified image at the specified location and with the specified size.
Public methodDrawImage(Image, Rectangle, Rectangle, GraphicsUnit, ImageAttributes)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, RectangleF, RectangleF, GraphicsUnit, ImageAttributes)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Int32, Int32, Int32, Int32)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImage(Image, Single, Single, Single, Single)
Draws the specified Image at the specified location and with the specified size.
Public methodDrawImageUnscaled(Image, Point)
Draws a specified image using its original physical size at a specified location.
Public methodDrawImageUnscaled(Image, Rectangle)
Draws a specified image using its original physical size at a specified location.
Public methodDrawImageUnscaled(Image, Int32, Int32)
Draws the specified image using its original physical size at the location specified by a coordinate pair.
Public methodDrawImageUnscaled(Image, Int32, Int32, Int32, Int32)
Draws a specified image using its original physical size at a specified location.
Public methodDrawImageUnscaledAndClipped
Draws the specified image without scaling and clips it, if necessary, to fit in the specified rectangle.
Public methodCode exampleDrawLine(Pen, Point, Point)
Draws a line connecting two Point structures.
Public methodDrawLine(Pen, PointF, PointF)
Draws a line connecting two PointF structures.
Public methodDrawLine(Pen, Int32, Int32, Int32, Int32)
Draws a line connecting the two points specified by the coordinate pairs.
Public methodDrawLine(Pen, Single, Single, Single, Single)
Draws a line connecting the two points specified by the coordinate pairs.
Public methodDrawLines(Pen, Point)
Draws a series of line segments that connect an array of Point structures.
Public methodDrawLines(Pen, PointF)
Draws a series of line segments that connect an array of PointF structures.
Public methodCode exampleDrawPath
Draws a GraphicsPath.
Public methodCode exampleDrawPie(Pen, Rectangle, Single, Single)
Draws a pie shape defined by an ellipse specified by a Rectangle structure and two radial lines.
Public methodDrawPie(Pen, RectangleF, Single, Single)
Draws a pie shape defined by an ellipse specified by a RectangleF structure and two radial lines.
Public methodDrawPie(Pen, Int32, Int32, Int32, Int32, Int32, Int32)
Draws a pie shape defined by an ellipse specified by a coordinate pair, a width, a height, and two radial lines.
Public methodDrawPie(Pen, Single, Single, Single, Single, Single, Single)
Draws a pie shape defined by an ellipse specified by a coordinate pair, a width, a height, and two radial lines.
Public methodCode exampleDrawPolygon(Pen, Point)
Draws a polygon defined by an array of Point structures.
Public methodDrawPolygon(Pen, PointF)
Draws a polygon defined by an array of PointF structures.
Public methodCode exampleDrawRectangle(Pen, Rectangle)
Draws a rectangle specified by a Rectangle structure.
Public methodDrawRectangle(Pen, RectangleF)
Draws a rectangle specified by a RectangleF structure.
Public methodDrawRectangle(Pen, Int32, Int32, Int32, Int32)
Draws a rectangle specified by a coordinate pair, a width, and a height.
Public methodDrawRectangle(Pen, Single, Single, Single, Single)
Draws a rectangle specified by a coordinate pair, a width, and a height.
Public methodCode exampleDrawRectangles(Pen, Rectangle)
Draws a series of rectangles specified by Rectangle structures.
Public methodDrawRectangles(Pen, RectangleF)
Draws a series of rectangles specified by RectangleF structures.
Public methodCode exampleDrawString(String, Font, Brush, PointF)
Draws the specified text string at the specified location with the specified Brush and Font objects.
Public methodDrawString(String, Font, Brush, RectangleF)
Draws the specified text string in the specified rectangle with the specified Brush and Font objects.
Public methodDrawString(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.
Public methodDrawString(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.
Public methodDrawString(String, Font, Brush, Single, Single)
Draws the specified text string at the specified location with the specified Brush and Font objects.
Public methodDrawString(String, Font, Brush, Single, Single, 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.
Public methodEndUpdate
Finishes caching of the graphics operations started after BeginUpdate was called. The preceding graphics operations will be applied at once when calling this method.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodFillClosedCurve(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.
Public methodFillClosedCurve(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.
Public methodFillClosedCurve(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.
Public methodFillClosedCurve(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.
Public methodFillClosedCurve(Brush, Point, FillMode, Single)
Fills the interior of a closed cardinal spline curve defined by an array of Point structures using the specified fill mode and tension.
Public methodFillClosedCurve(Brush, PointF, FillMode, Single)
Fills the interior of a closed cardinal spline curve defined by an array of PointF structures using the specified fill mode and tension.
Public methodFillEllipse(Brush, Rectangle)
Fills the interior of an ellipse defined by a bounding rectangle specified by a Rectangle structure.
Public methodFillEllipse(Brush, RectangleF)
Fills the interior of an ellipse defined by a bounding rectangle specified by a RectangleF structure.
Public methodFillEllipse(Brush, Int32, Int32, Int32, Int32)
Fills the interior of an ellipse defined by a bounding rectangle specified by a pair of coordinates, a width, and a height.
Public methodFillEllipse(Brush, Single, Single, Single, Single)
Fills the interior of an ellipse defined by a bounding rectangle specified by a pair of coordinates, a width, and a height.
Public methodFillPath
Fills the interior of a GraphicsPath.
Public methodCode exampleFillPie(Brush, Rectangle, Single, Single)
Fills the interior of a pie section defined by an ellipse specified by a RectangleF structure and two radial lines.
Public methodFillPie(Brush, RectangleF, Single, Single)
Fills the interior of a pie section defined by an ellipse specified by a RectangleF structure and two radial lines.
Public methodFillPie(Brush, Int32, Int32, Int32, Int32, Int32, Int32)
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.
Public methodFillPie(Brush, Single, Single, Single, Single, Single, Single)
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.
Public methodFillPolygon(Brush, Point)
Fills the interior of a polygon defined by an array of points specified by Point structures and Alternate.
Public methodFillPolygon(Brush, PointF)
Fills the interior of a polygon defined by an array of points specified by PointF structures and Alternate.
Public methodFillPolygon(Brush, Point, FillMode)
Fills the interior of a polygon defined by an array of points specified by Point structures using the specified fill mode.
Public methodFillPolygon(Brush, PointF, FillMode)
Fills the interior of a polygon defined by an array of points specified by PointF structures using the specified fill mode.
Public methodFillRectangle(Brush, Rectangle)
Fills the interior of a rectangle specified by a Rectangle structure.
Public methodFillRectangle(Brush, RectangleF)
Fills the interior of a rectangle specified by a RectangleF structure.
Public methodFillRectangle(Brush, Int32, Int32, Int32, Int32)
Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.
Public methodFillRectangle(Brush, Single, Single, Single, Single)
Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.
Public methodFillRectangles(Brush, Rectangle)
Fills the interiors of a series of rectangles specified by Rectangle structures.
Public methodFillRectangles(Brush, RectangleF)
Fills the interiors of a series of rectangles specified by RectangleF structures.
Public methodFillRegion
Fills the interior of a Region.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodMultiplyTransform(Matrix)
Multiplies the Matrix that represents the local geometric transform of this Graphics by the specified Matrix by prepending the specified Matrix.
Public methodMultiplyTransform(Matrix, MatrixOrder)
Multiplies the Matrix that represents the local geometric transform of this Graphics by the specified Matrix in the specified order.
Public methodResetTransform
Resets the Transform property to identity.
Public methodRotateTransform(Single)
Rotates the local geometric transform by the specified amount. This method prepends the rotation to the transform.
Public methodRotateTransform(Single, MatrixOrder)
Rotates the local geometric transform by the specified amount in the specified order.
Public methodScaleTransform(Single, Single)
Scales the local geometric transform by the specified amounts. This method prepends the scaling matrix to the transform.
Public methodScaleTransform(Single, Single, MatrixOrder)
Scales the local geometric transform by the specified amounts in the specified order.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTranslateTransform(Single, Single)
Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.
Public methodTranslateTransform(Single, Single, 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