Class Graphics

Class Graphics

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.2.0)

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

public sealed class Graphics

Inheritance

objectGraphics

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

## Constructors

### <a id="Aspose_Imaging_Graphics__ctor_Aspose_Imaging_Image_"></a> Graphics\(Image\)

Initializes a new instance of the Aspose.Imaging.Graphics class.

```csharp
public Graphics(Image sourceImage)

Parameters

sourceImage Image

The source image.

Properties

Clip

Gets or sets the clip region.

public Region Clip { get; set; }

Property Value

Region

CompositingQuality

Gets or sets the compositing quality.

public CompositingQuality CompositingQuality { get; set; }

Property Value

CompositingQuality

DpiX

Gets the horizontal resolution of this Aspose.Imaging.Graphics.

public float DpiX { get; }

Property Value

float

DpiY

Gets the vertical resolution of this Aspose.Imaging.Graphics.

public float DpiY { get; }

Property Value

float

Image

Gets the image.

public Image Image { get; }

Property Value

Image

InterpolationMode

Gets or sets the interpolation mode.

public InterpolationMode InterpolationMode { get; set; }

Property Value

InterpolationMode

IsInBeginUpdateCall

Gets a value indicating whether graphics is in BeginUpdate call state.

public bool IsInBeginUpdateCall { get; }

Property Value

bool

PageScale

Gets or sets the scaling between world units and page units for this Aspose.Imaging.Graphics.

public float PageScale { get; set; }

Property Value

float

PageUnit

Gets or sets the unit of measure used for page coordinates in this Aspose.Imaging.Graphics.

public GraphicsUnit PageUnit { get; set; }

Property Value

GraphicsUnit

PaintableImageOptions

Gets or sets image options, used to create paintable vactor images to draw.

public ImageOptionsBase PaintableImageOptions { get; set; }

Property Value

ImageOptionsBase

SmoothingMode

Gets or sets the smoothing mode.

public SmoothingMode SmoothingMode { get; set; }

Property Value

SmoothingMode

TextRenderingHint

Gets or sets the text rendering hint.

public TextRenderingHint TextRenderingHint { get; set; }

Property Value

TextRenderingHint

Transform

Gets or sets a copy of the geometric world transformation for this Aspose.Imaging.Graphics.

public Matrix Transform { get; set; }

Property Value

Matrix

Methods

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.

public void BeginUpdate()

Remarks

Note the effects after BeginUpdate is called will not be applied in case EndUpdate is not called.

Clear(Color)

Clears the graphics surface using the specified color.

public void Clear(Color color)

Parameters

color Color

The color to clear the graphics surface by.

Examples

This examples make use of GraphicsPath and Graphics class to create and manipulate Figures on an Image surface. Example creates a new Image (of type Tiff), clears the surface and draws paths with the help of GraphicsPath class. At the end DrawPath method exposed by Graphics class is called to render the paths on surface.```csharp [C#]

                                                                                                                                                                                                                                                                                                                                         //Create an instance of FileStream
                                                                                                                                                                                                                                                                                                                                         using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.tiff", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                                                                                                                             //Create an instance of TiffOptions and set its various properties
                                                                                                                                                                                                                                                                                                                                             Aspose.Imaging.ImageOptions.TiffOptions tiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);

                                                                                                                                                                                                                                                                                                                                             //Set the source for the instance of ImageOptions
                                                                                                                                                                                                                                                                                                                                             tiffOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

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

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

                                                                                                                                                                                                                                                                                                                                                 //Create an instance of GraphicsPath class
                                                                                                                                                                                                                                                                                                                                                 Aspose.Imaging.GraphicsPath graphicspath = new Aspose.Imaging.GraphicsPath();

                                                                                                                                                                                                                                                                                                                                                 //Create an instance of Figure class
                                                                                                                                                                                                                                                                                                                                                 Aspose.Imaging.Figure figure = new Aspose.Imaging.Figure();

                                                                                                                                                                                                                                                                                                                                                 //Add Shapes to Figure object
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.RectangleShape(new Aspose.Imaging.RectangleF(10f, 10f, 300f, 300f)));
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.EllipseShape(new Aspose.Imaging.RectangleF(50f, 50f, 300f, 300f)));
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.PieShape(new Aspose.Imaging.RectangleF(new Aspose.Imaging.PointF(250f, 250f), new Aspose.Imaging.SizeF(200f, 200f)), 0f, 45f));

                                                                                                                                                                                                                                                                                                                                                 //Add Figure object to GraphicsPath
                                                                                                                                                                                                                                                                                                                                                 graphicspath.AddFigure(figure);

                                                                                                                                                                                                                                                                                                                                                 //Draw path with Pen object of color Black
                                                                                                                                                                                                                                                                                                                                                 graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), graphicspath);

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

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```csharp
[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();
                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                }

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.

public void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the arc.

x float

The x-coordinate of the upper-left corner of the rectangle that defines the ellipse.

y float

The y-coordinate of the upper-left corner of the rectangle that defines the ellipse.

width float

Width of the rectangle that defines the ellipse.

height float

Height of the rectangle that defines the ellipse.

startAngle float

Angle in degrees measured clockwise from the x-axis to the starting point of the arc.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.

Exceptions

ArgumentNullException

pen is null.

DrawArc(Pen, RectangleF, float, float)

Draws an arc representing a portion of an ellipse specified by a Aspose.Imaging.RectangleF structure.

public void DrawArc(Pen pen, RectangleF rect, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the arc.

rect RectangleF

Aspose.Imaging.RectangleF structure that defines the boundaries of the ellipse.

startAngle float

Angle in degrees measured clockwise from the x-axis to the starting point of the arc.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.

Exceptions

ArgumentNullException

pen is null

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.

public void DrawArc(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the arc.

x int

The x-coordinate of the upper-left corner of the rectangle that defines the ellipse.

y int

The y-coordinate of the upper-left corner of the rectangle that defines the ellipse.

width int

Width of the rectangle that defines the ellipse.

height int

Height of the rectangle that defines the ellipse.

startAngle int

Angle in degrees measured clockwise from the x-axis to the starting point of the arc.

sweepAngle int

Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.

Exceptions

ArgumentNullException

pen is null.

DrawArc(Pen, Rectangle, float, float)

Draws an arc representing a portion of an ellipse specified by a Aspose.Imaging.Rectangle structure.

public void DrawArc(Pen pen, Rectangle rect, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the arc.

rect Rectangle

Aspose.Imaging.RectangleF structure that defines the boundaries of the ellipse.

startAngle float

Angle in degrees measured clockwise from the x-axis to the starting point of the arc.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawBezier_Aspose_Imaging_Pen_System_Single_System_Single_System_Single_System_Single_System_Single_System_Single_System_Single_System_Single_"></a> 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.

```csharp
public void DrawBezier(Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the curve.

x1 float

The x-coordinate of the starting point of the curve.

y1 float

The y-coordinate of the starting point of the curve.

x2 float

The x-coordinate of the first control point of the curve.

y2 float

The y-coordinate of the first control point of the curve.

x3 float

The x-coordinate of the second control point of the curve.

y3 float

The y-coordinate of the second control point of the curve.

x4 float

The x-coordinate of the ending point of the curve.

y4 float

The y-coordinate of the ending point of the curve.

Exceptions

ArgumentNullException

pen is null.

DrawBezier(Pen, PointF, PointF, PointF, PointF)

Draws a Bézier spline defined by four Aspose.Imaging.PointF structures.

public void DrawBezier(Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the curve.

pt1 PointF

Aspose.Imaging.PointF structure that represents the starting point of the curve.

pt2 PointF

Aspose.Imaging.PointF structure that represents the first control point for the curve.

pt3 PointF

Aspose.Imaging.PointF structure that represents the second control point for the curve.

pt4 PointF

Aspose.Imaging.PointF structure that represents the ending point of the curve.

Exceptions

ArgumentNullException

pen is null.

DrawBezier(Pen, Point, Point, Point, Point)

Draws a Bézier spline defined by four Aspose.Imaging.Point structures.

public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)

Parameters

pen Pen

Aspose.Imaging.Pen structure that determines the color, width, and style of the curve.

pt1 Point

Aspose.Imaging.Point structure that represents the starting point of the curve.

pt2 Point

Aspose.Imaging.Point structure that represents the first control point for the curve.

pt3 Point

Aspose.Imaging.Point structure that represents the second control point for the curve.

pt4 Point

Aspose.Imaging.Point structure that represents the ending point of the curve.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawBeziers_Aspose_Imaging_Pen_Aspose_Imaging_Point___"></a> DrawBeziers\(Pen, Point\[\]\)

Draws a series of Bézier splines from an array of Aspose.Imaging.Point structures.

```csharp
public void DrawBeziers(Pen pen, Point[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that represent the points that determine the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawBeziers(Pen, PointF[])

Draws a series of Bézier splines from an array of Aspose.Imaging.PointF structures.

public void DrawBeziers(Pen pen, PointF[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the points that determine the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawClosedCurve(Pen, PointF[])

Draws a closed cardinal spline defined by an array of Aspose.Imaging.PointF structures. This method uses a default tension of 0.5 and Aspose.Imaging.FillMode.Alternate fill mode.

public void DrawClosedCurve(Pen pen, PointF[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawClosedCurve(Pen, PointF[], float)

Draws a closed cardinal spline defined by an array of Aspose.Imaging.PointF structures using a specified tension. This method uses a default Aspose.Imaging.FillMode.Alternate fill mode.

public void DrawClosedCurve(Pen pen, PointF[] points, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawClosedCurve(Pen, Point[])

Draws a closed cardinal spline defined by an array of Aspose.Imaging.Point structures. This method uses a default tension of 0.5 and Aspose.Imaging.FillMode.Alternate fill mode.

public void DrawClosedCurve(Pen pen, Point[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawClosedCurve(Pen, Point[], float)

Draws a closed cardinal spline defined by an array of Aspose.Imaging.Point structures using a specified tension. This method uses a default Aspose.Imaging.FillMode.Alternate fill mode.

public void DrawClosedCurve(Pen pen, Point[] points, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, PointF[])

Draws a cardinal spline through a specified array of Aspose.Imaging.PointF structures. This method uses a default tension of 0.5.

public void DrawCurve(Pen pen, PointF[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, PointF[], float)

Draws a cardinal spline through a specified array of Aspose.Imaging.PointF structures using a specified tension.

public void DrawCurve(Pen pen, PointF[] points, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the points that define the curve.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, PointF[], int, int)

Draws a cardinal spline through a specified array of Aspose.Imaging.PointF structures. The drawing begins offset from the beginning of the array. This method uses a default tension of 0.5.

public void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

offset int

Offset from the first element in the array of the points parameter to the starting point in the curve.

numberOfSegments int

Number of segments after the starting point to include in the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, PointF[], int, int, float)

Draws a cardinal spline through a specified array of Aspose.Imaging.PointF structures using a specified tension. The drawing begins offset from the beginning of the array.

public void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

offset int

Offset from the first element in the array of the points parameter to the starting point in the curve.

numberOfSegments int

Number of segments after the starting point to include in the curve.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, Point[])

Draws a cardinal spline through a specified array of Aspose.Imaging.Point structures.

public void DrawCurve(Pen pen, Point[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.
        -or-
        <code class="paramref">points</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawCurve_Aspose_Imaging_Pen_Aspose_Imaging_Point___System_Single_"></a> DrawCurve\(Pen, Point\[\], float\)

Draws a cardinal spline through a specified array of Aspose.Imaging.Point structures using a specified tension.

```csharp
public void DrawCurve(Pen pen, Point[] points, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawCurve(Pen, Point[], int, int, float)

Draws a cardinal spline through a specified array of Aspose.Imaging.Point structures using a specified tension.

public void DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and height of the curve.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

offset int

Offset from the first element in the array of the points parameter to the starting point in the curve.

numberOfSegments int

Number of segments after the starting point to include in the curve.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawEllipse(Pen, RectangleF)

Draws an ellipse defined by a bounding Aspose.Imaging.RectangleF.

public void DrawEllipse(Pen pen, RectangleF rect)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the ellipse.

rect RectangleF

Aspose.Imaging.RectangleF structure that defines the boundaries of the ellipse.

Exceptions

ArgumentNullException

pen is null.

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.

public void DrawEllipse(Pen pen, float x, float y, float width, float height)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the ellipse.

x float

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

y float

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

width float

Width of the bounding rectangle that defines the ellipse.

height float

Height of the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

pen is null.

DrawEllipse(Pen, Rectangle)

Draws an ellipse specified by a bounding Aspose.Imaging.Rectangle structure.

public void DrawEllipse(Pen pen, Rectangle rect)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the ellipse.

rect Rectangle

Aspose.Imaging.Rectangle structure that defines the boundaries of the ellipse.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawEllipse_Aspose_Imaging_Pen_System_Int32_System_Int32_System_Int32_System_Int32_"></a> 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.

```csharp
public void DrawEllipse(Pen pen, int x, int y, int width, int height)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the ellipse.

x int

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

y int

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

width int

Width of the bounding rectangle that defines the ellipse.

height int

Height of the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

pen is null.

DrawImage(Image, PointF)

Draws the specified Aspose.Imaging.Graphics.Image, using its original physical size, at the specified location.

public void DrawImage(Image sourceImage, PointF point)

Parameters

sourceImage Image

The image to draw with.

point PointF

Aspose.Imaging.PointF structure that represents the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, float, float)

Draws the specified Aspose.Imaging.Graphics.Image, using its original physical size, at the specified location.

public void DrawImage(Image sourceImage, float x, float y)

Parameters

sourceImage Image

The image to draw with.

x float

The x-coordinate of the upper-left corner of the drawn image.

y float

The y-coordinate of the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, RectangleF)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, RectangleF rect)

Parameters

sourceImage Image

The image to draw with.

rect RectangleF

Aspose.Imaging.RectangleF structure that specifies the location and size of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Rectangle, GraphicsUnit)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, Rectangle rectDestination, GraphicsUnit graphicsUnit)

Parameters

sourceImage Image

The image to draw with.

rectDestination Rectangle

The destination rectangle.

graphicsUnit GraphicsUnit

The graphics unit.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, RectangleF, GraphicsUnit)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, RectangleF rectDestination, GraphicsUnit graphicsUnit)

Parameters

sourceImage Image

The image to draw with.

rectDestination RectangleF

The destination rectangle.

graphicsUnit GraphicsUnit

The graphics unit.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Rectangle, GraphicsUnit, ImageAttributes)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, Rectangle rectDestination, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)

Parameters

sourceImage Image

The image to draw with.

rectDestination Rectangle

The destination rectangle.

graphicsUnit GraphicsUnit

The graphics unit.

imageAttributes ImageAttributes

The image attributes.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, RectangleF, GraphicsUnit, ImageAttributes)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, RectangleF rectDestination, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)

Parameters

sourceImage Image

The image to draw with.

rectDestination RectangleF

The destination rectangle to draw in.

graphicsUnit GraphicsUnit

The graphics unit.

imageAttributes ImageAttributes

The image attributes.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, Rectangle rectSource, Rectangle rectDestination, GraphicsUnit graphicsUnit)

Parameters

sourceImage Image

The image to draw with.

rectSource Rectangle

The rect source.

rectDestination Rectangle

The rect destination.

graphicsUnit GraphicsUnit

The graphics unit.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, RectangleF rectSource, RectangleF rectDestination, GraphicsUnit graphicsUnit)

Parameters

sourceImage Image

The image to draw with.

rectSource RectangleF

The rect source.

rectDestination RectangleF

The rect destination.

graphicsUnit GraphicsUnit

The graphics unit.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit, ImageAttributes)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, Rectangle rectSource, Rectangle rectDestination, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)

Parameters

sourceImage Image

The image to draw with.

rectSource Rectangle

The rect source.

rectDestination Rectangle

The rect destination.

graphicsUnit GraphicsUnit

The graphics unit.

imageAttributes ImageAttributes

The image attributes.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit, ImageAttributes)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, RectangleF rectSource, RectangleF rectDestination, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)

Parameters

sourceImage Image

The image to draw with.

rectSource RectangleF

The source rectangle.

rectDestination RectangleF

The destination rectangle.

graphicsUnit GraphicsUnit

The graphics unit to use.

imageAttributes ImageAttributes

The image attributes to use.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Point[])

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, Point[] destPoints)

Parameters

image Image

The image to draw.

destPoints Point[]

Array of three PointF structures that define a parallelogram.

DrawImage(Image, Point[], Rectangle)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect)

Parameters

image Image

The image to draw.

destPoints Point[]

Array of three PointF structures that define a parallelogram.

srcRect Rectangle

The source rectangle.

DrawImage(Image, Point[], Rectangle, GraphicsUnit)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)

Parameters

image Image

The image to draw.

destPoints Point[]

Array of three PointF structures that define a parallelogram.

srcRect Rectangle

The source rectangle.

srcUnit GraphicsUnit

The units of measure.

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttributes)

Parameters

image Image

The image to draw.

destPoints Point[]

Array of three PointF structures that define a parallelogram.

srcRect Rectangle

The source rectangle.

srcUnit GraphicsUnit

The units of measure.

imageAttributes ImageAttributes

The image attributes.

DrawImage(Image, PointF[])

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, PointF[] destPoints)

Parameters

image Image

The image to draw.

destPoints PointF[]

Array of three PointF structures that define a parallelogram.

Exceptions

ArgumentNullException

image

DrawImage(Image, PointF[], RectangleF)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect)

Parameters

image Image

The image to draw.

destPoints PointF[]

Array of three PointF structures that define a parallelogram.

srcRect RectangleF

The source rectangle.

DrawImage(Image, PointF[], RectangleF, GraphicsUnit)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)

Parameters

image Image

The image to draw.

destPoints PointF[]

Array of three PointF structures that define a parallelogram.

srcRect RectangleF

The source rectangle.

srcUnit GraphicsUnit

The units of measure.

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)

Draws the specified portion of the specified image at the specified location and with the specified size.

public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttributes)

Parameters

image Image

The image to draw.

destPoints PointF[]

Array of three PointF structures that define a parallelogram.

srcRect RectangleF

The source rectangle.

srcUnit GraphicsUnit

The units of measure.

imageAttributes ImageAttributes

The image attributes.

DrawImage(Image, float, float, float, float)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, float x, float y, float width, float height)

Parameters

sourceImage Image

The image to draw with.

x float

The x-coordinate of the upper-left corner of the drawn image.

y float

The y-coordinate of the upper-left corner of the drawn image.

width float

Width of the drawn image.

height float

Height of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Point)

Draws the specified Aspose.Imaging.Graphics.Image, using its original physical size, at the specified location.

public void DrawImage(Image sourceImage, Point point)

Parameters

sourceImage Image

The image to draw with.

point Point

Aspose.Imaging.Point structure that represents the location of the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, int, int)

Draws the specified image, using its original physical size, at the location specified by a coordinate pair.

public void DrawImage(Image sourceImage, int x, int y)

Parameters

sourceImage Image

The image to draw with.

x int

The x-coordinate of the upper-left corner of the drawn image.

y int

The y-coordinate of the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, Rectangle)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, Rectangle rect)

Parameters

sourceImage Image

The image to draw with.

rect Rectangle

Aspose.Imaging.Rectangle structure that specifies the location and size of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImage(Image, int, int, int, int)

Draws the specified Aspose.Imaging.Graphics.Image at the specified location and with the specified size.

public void DrawImage(Image sourceImage, int x, int y, int width, int height)

Parameters

sourceImage Image

The image to draw with.

x int

The x-coordinate of the upper-left corner of the drawn image.

y int

The y-coordinate of the upper-left corner of the drawn image.

width int

Width of the drawn image.

height int

Height of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImageUnscaled(Image, Point)

Draws a specified image using its original physical size at a specified location.

public void DrawImageUnscaled(Image sourceImage, Point point)

Parameters

sourceImage Image

The image to draw with.

point Point

Aspose.Imaging.Point structure that specifies the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImageUnscaled(Image, int, int)

Draws the specified image using its original physical size at the location specified by a coordinate pair.

public void DrawImageUnscaled(Image sourceImage, int x, int y)

Parameters

sourceImage Image

The image to draw with.

x int

The x-coordinate of the upper-left corner of the drawn image.

y int

The y-coordinate of the upper-left corner of the drawn image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImageUnscaled(Image, Rectangle)

Draws a specified image using its original physical size at a specified location.

public void DrawImageUnscaled(Image sourceImage, Rectangle rect)

Parameters

sourceImage Image

The image to draw with.

rect Rectangle

Aspose.Imaging.Rectangle that specifies the upper-left corner of the drawn image. The X and Y properties of the rectangle specify the upper-left corner. The Width and Height properties are ignored.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImageUnscaled(Image, int, int, int, int)

Draws a specified image using its original physical size at a specified location.

public void DrawImageUnscaled(Image sourceImage, int x, int y, int width, int height)

Parameters

sourceImage Image

The image to draw with.

x int

The x-coordinate of the upper-left corner of the drawn image.

y int

The y-coordinate of the upper-left corner of the drawn image.

width int

The parameter is not used.

height int

The parameter is not used.

Exceptions

ArgumentNullException

sourceImage is null.

DrawImageUnscaledAndClipped(Image, Rectangle)

Draws the specified image without scaling and clips it, if necessary, to fit in the specified rectangle.

public void DrawImageUnscaledAndClipped(Image sourceImage, Rectangle rect)

Parameters

sourceImage Image

The image to draw with.

rect Rectangle

The Aspose.Imaging.Rectangle in which to draw the image.

Exceptions

ArgumentNullException

sourceImage is null.

DrawLine(Pen, Point, Point)

Draws a line connecting two Aspose.Imaging.Point structures.

public void DrawLine(Pen pen, Point point1, Point point2)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line.

point1 Point

Aspose.Imaging.Point structure that represents the first point to connect.

point2 Point

Aspose.Imaging.Point structure that represents the second point to connect.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawLine_Aspose_Imaging_Pen_Aspose_Imaging_PointF_Aspose_Imaging_PointF_"></a> DrawLine\(Pen, PointF, PointF\)

Draws a line connecting two Aspose.Imaging.PointF structures.

```csharp
public void DrawLine(Pen pen, PointF point1, PointF point2)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line.

point1 PointF

Aspose.Imaging.PointF structure that represents the first point to connect.

point2 PointF

Aspose.Imaging.PointF structure that represents the second point to connect.

Exceptions

ArgumentNullException

pen is null.

DrawLine(Pen, int, int, int, int)

Draws a line connecting the two points specified by the coordinate pairs.

public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line.

x1 int

The x-coordinate of the first point.

y1 int

The y-coordinate of the first point.

x2 int

The x-coordinate of the second point.

y2 int

The y-coordinate of the second point.

Exceptions

ArgumentNullException

pen is null.

DrawLine(Pen, float, float, float, float)

Draws a line connecting the two points specified by the coordinate pairs.

public void DrawLine(Pen pen, float x1, float y1, float x2, float y2)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line.

x1 float

The x-coordinate of the first point.

y1 float

The y-coordinate of the first point.

x2 float

The x-coordinate of the second point.

y2 float

The y-coordinate of the second point.

Exceptions

ArgumentNullException

pen is null.

DrawLines(Pen, Point[])

Draws a series of line segments that connect an array of Aspose.Imaging.Point structures.

public void DrawLines(Pen pen, Point[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line segments.

points Point[]

Array of Aspose.Imaging.Point structures that represent the points to connect.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

ArgumentException

The points array contains less than 2 points.

DrawLines(Pen, PointF[])

Draws a series of line segments that connect an array of Aspose.Imaging.PointF structures.

public void DrawLines(Pen pen, PointF[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the line segments.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the points to connect.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

ArgumentException

The points array contains less than 2 points.

DrawPath(Pen, GraphicsPath)

Draws a Aspose.Imaging.GraphicsPath.

public void DrawPath(Pen pen, GraphicsPath path)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the path.

path GraphicsPath

Aspose.Imaging.GraphicsPath to draw.

Examples

This examples make use of GraphicsPath and Graphics class to create and manipulate Figures on an Image surface. Example creates a new Image (of type Tiff), clears the surface and draws paths with the help of GraphicsPath class. At the end DrawPath method exposed by Graphics class is called to render the paths on surface.```csharp [C#]

                                                                                                                                                                                                                                                                                                                                         //Create an instance of FileStream
                                                                                                                                                                                                                                                                                                                                         using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.tiff", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                                                                                                                             //Create an instance of TiffOptions and set its various properties
                                                                                                                                                                                                                                                                                                                                             Aspose.Imaging.ImageOptions.TiffOptions tiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);

                                                                                                                                                                                                                                                                                                                                             //Set the source for the instance of ImageOptions
                                                                                                                                                                                                                                                                                                                                             tiffOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

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

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

                                                                                                                                                                                                                                                                                                                                                 //Create an instance of GraphicsPath class
                                                                                                                                                                                                                                                                                                                                                 Aspose.Imaging.GraphicsPath graphicspath = new Aspose.Imaging.GraphicsPath();

                                                                                                                                                                                                                                                                                                                                                 //Create an instance of Figure class
                                                                                                                                                                                                                                                                                                                                                 Aspose.Imaging.Figure figure = new Aspose.Imaging.Figure();

                                                                                                                                                                                                                                                                                                                                                 //Add Shapes to Figure object
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.RectangleShape(new Aspose.Imaging.RectangleF(10f, 10f, 300f, 300f)));
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.EllipseShape(new Aspose.Imaging.RectangleF(50f, 50f, 300f, 300f)));
                                                                                                                                                                                                                                                                                                                                                 figure.AddShape(new Aspose.Imaging.Shapes.PieShape(new Aspose.Imaging.RectangleF(new Aspose.Imaging.PointF(250f, 250f), new Aspose.Imaging.SizeF(200f, 200f)), 0f, 45f));

                                                                                                                                                                                                                                                                                                                                                 //Add Figure object to GraphicsPath
                                                                                                                                                                                                                                                                                                                                                 graphicspath.AddFigure(figure);

                                                                                                                                                                                                                                                                                                                                                 //Draw path with Pen object of color Black
                                                                                                                                                                                                                                                                                                                                                 graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), graphicspath);

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

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.
        -or-
        <code class="paramref">path</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawPie_Aspose_Imaging_Pen_Aspose_Imaging_RectangleF_System_Single_System_Single_"></a> DrawPie\(Pen, RectangleF, float, float\)

Draws a pie shape defined by an ellipse specified by a Aspose.Imaging.RectangleF structure and two radial lines.

```csharp
public void DrawPie(Pen pen, RectangleF rect, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the pie shape.

rect RectangleF

Aspose.Imaging.RectangleF structure that represents the bounding rectangle that defines the ellipse from which the pie shape comes.

startAngle float

Angle measured in degrees clockwise from the x-axis to the first side of the pie shape.

sweepAngle float

Angle measured in degrees clockwise from the startAngle parameter to the second side of the pie shape.

Exceptions

ArgumentNullException

pen is null.

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.

public void DrawPie(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the pie shape.

x float

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie shape comes.

y float

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie shape comes.

width float

Width of the bounding rectangle that defines the ellipse from which the pie shape comes.

height float

Height of the bounding rectangle that defines the ellipse from which the pie shape comes.

startAngle float

Angle measured in degrees clockwise from the x-axis to the first side of the pie shape.

sweepAngle float

Angle measured in degrees clockwise from the startAngle parameter to the second side of the pie shape.

Exceptions

ArgumentNullException

pen is null.

DrawPie(Pen, Rectangle, float, float)

Draws a pie shape defined by an ellipse specified by a Aspose.Imaging.Rectangle structure and two radial lines.

public void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the pie shape.

rect Rectangle

Aspose.Imaging.Rectangle structure that represents the bounding rectangle that defines the ellipse from which the pie shape comes.

startAngle float

Angle measured in degrees clockwise from the x-axis to the first side of the pie shape.

sweepAngle float

Angle measured in degrees clockwise from the startAngle parameter to the second side of the pie shape.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawPie_Aspose_Imaging_Pen_System_Int32_System_Int32_System_Int32_System_Int32_System_Int32_System_Int32_"></a> 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.

```csharp
public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the pie shape.

x int

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie shape comes.

y int

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie shape comes.

width int

Width of the bounding rectangle that defines the ellipse from which the pie shape comes.

height int

Height of the bounding rectangle that defines the ellipse from which the pie shape comes.

startAngle int

Angle measured in degrees clockwise from the x-axis to the first side of the pie shape.

sweepAngle int

Angle measured in degrees clockwise from the startAngle parameter to the second side of the pie shape.

Exceptions

ArgumentNullException

pen is null.

DrawPolygon(Pen, PointF[])

Draws a polygon defined by an array of Aspose.Imaging.PointF structures.

public void DrawPolygon(Pen pen, PointF[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the polygon.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the vertices of the polygon.

Exceptions

ArgumentNullException

pen is null. -or- points is null.

DrawPolygon(Pen, Point[])

Draws a polygon defined by an array of Aspose.Imaging.Point structures.

public void DrawPolygon(Pen pen, Point[] points)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the polygon.

points Point[]

Array of Aspose.Imaging.Point structures that represent the vertices of the polygon.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawRectangle_Aspose_Imaging_Pen_Aspose_Imaging_RectangleF_"></a> DrawRectangle\(Pen, RectangleF\)

Draws a rectangle specified by a Aspose.Imaging.RectangleF structure.

```csharp
public void DrawRectangle(Pen pen, RectangleF rect)

Parameters

pen Pen

A Aspose.Imaging.Pen that determines the color, width, and style of the rectangle.

rect RectangleF

A Aspose.Imaging.RectangleF structure that represents the rectangle to draw.

Exceptions

ArgumentNullException

pen is null.

DrawRectangle(Pen, Rectangle)

Draws a rectangle specified by a Aspose.Imaging.Rectangle structure.

public void DrawRectangle(Pen pen, Rectangle rect)

Parameters

pen Pen

A Aspose.Imaging.Pen that determines the color, width, and style of the rectangle.

rect Rectangle

A Aspose.Imaging.Rectangle structure that represents the rectangle to draw.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawRectangle_Aspose_Imaging_Pen_System_Single_System_Single_System_Single_System_Single_"></a> DrawRectangle\(Pen, float, float, float, float\)

Draws a rectangle specified by a coordinate pair, a width, and a height.

```csharp
public void DrawRectangle(Pen pen, float x, float y, float width, float height)

Parameters

pen Pen

A Aspose.Imaging.Pen that determines the color, width, and style of the rectangle.

x float

The x-coordinate of the upper-left corner of the rectangle to draw.

y float

The y-coordinate of the upper-left corner of the rectangle to draw.

width float

The width of the rectangle to draw.

height float

The height of the rectangle to draw.

Exceptions

ArgumentNullException

pen is null.

DrawRectangle(Pen, int, int, int, int)

Draws a rectangle specified by a coordinate pair, a width, and a height.

public void DrawRectangle(Pen pen, int x, int y, int width, int height)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the rectangle.

x int

The x-coordinate of the upper-left corner of the rectangle to draw.

y int

The y-coordinate of the upper-left corner of the rectangle to draw.

width int

Width of the rectangle to draw.

height int

Height of the rectangle to draw.

Exceptions

ArgumentNullException

pen is null.

DrawRectangles(Pen, RectangleF[])

Draws a series of rectangles specified by Aspose.Imaging.RectangleF structures.

public void DrawRectangles(Pen pen, RectangleF[] rects)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the outlines of the rectangles.

rects RectangleF[]

Array of Aspose.Imaging.RectangleF structures that represent the rectangles to draw.

Exceptions

ArgumentNullException

pen is null. -or- rects is null.

DrawRectangles(Pen, Rectangle[])

Draws a series of rectangles specified by Aspose.Imaging.Rectangle structures.

public void DrawRectangles(Pen pen, Rectangle[] rects)

Parameters

pen Pen

Aspose.Imaging.Pen that determines the color, width, and style of the outlines of the rectangles.

rects Rectangle[]

Array of Aspose.Imaging.Rectangle structures that represent the rectangles to draw.

Examples

This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.```csharp [C#]

                                                                                                                                   //Create an instance of BmpOptions and set its various properties
                                                                                                                                   Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
                                                                                                                                   bmpOptions.BitsPerPixel = 24;

                                                                                                                                   //Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
                                                                                                                                   //Second Boolean parameter determines if the file to be created IsTemporal or not
                                                                                                                                   bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\sample.bmp", false);

                                                                                                                                   //Create an instance of Image at specified Path
                                                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
                                                                                                                                   {
                                                                                                                                       //Create an instance of Graphics and initialize it with Image object
                                                                                                                                       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

                                                                                                                                       //Clear the Graphics sutface with White Color
                                                                                                                                       graphics.Clear(Aspose.Imaging.Color.White);

                                                                                                                                       //Create an instance of Pen with color Red and width 5
                                                                                                                                       Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 5f);

                                                                                                                                       //Create an instance of HatchBrush and set its properties
                                                                                                                                       Aspose.Imaging.Brushes.HatchBrush brush = new Aspose.Imaging.Brushes.HatchBrush();
                                                                                                                                       brush.BackgroundColor = Aspose.Imaging.Color.Wheat;
                                                                                                                                       brush.ForegroundColor = Aspose.Imaging.Color.Red;

                                                                                                                                       //Create an instance of Pen
                                                                                                                                       //initialize it with HatchBrush object and width
                                                                                                                                       Aspose.Imaging.Pen brusedpen = new Pen(brush, 5);

                                                                                                                                       //Draw Rectangles by specifying Pen object
                                                                                                                                       graphics.DrawRectangles(pen, new[]
                                                                                                                                       {
                                                                                                                                           new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(210, 210), new Aspose.Imaging.Size(100, 100)),
                                                                                                                                           new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 110), new Aspose.Imaging.Size(100, 100)),
                                                                                                                                           new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 310), new Aspose.Imaging.Size(100, 100))
                                                                                                                                       });

                                                                                                                                       //Draw Rectangles by specifying Pen object
                                                                                                                                       graphics.DrawRectangles(brusedpen, new[]
                                                                                                                                       {
                                                                                                                                           new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(310, 110), new Aspose.Imaging.Size(100, 100)),
                                                                                                                                           new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(110, 310), new Aspose.Imaging.Size(100, 100))
                                                                                                                                       });

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

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">pen</code> is null.
        -or-
        <code class="paramref">rects</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawString_System_String_Aspose_Imaging_Font_Aspose_Imaging_Brush_System_Single_System_Single_"></a> DrawString\(string, Font, Brush, float, float\)

Draws the specified text string at the specified location with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects.

```csharp
public void DrawString(string s, Font font, Brush brush, float x, float y)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

x float

The x-coordinate of the upper-left corner of the drawn text.

y float

The y-coordinate of the upper-left corner of the drawn text.

Exceptions

ArgumentNullException

brush is null. -or- s is null.

DrawString(string, Font, Brush, PointF)

Draws the specified text string at the specified location with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects.

public void DrawString(string s, Font font, Brush brush, PointF point)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

point PointF

Aspose.Imaging.PointF structure that specifies the upper-left corner of the drawn text.

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```csharp [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();
                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                            }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">brush</code> is null.
        -or-
        <code class="paramref">s</code> is null.

### <a id="Aspose_Imaging_Graphics_DrawString_System_String_Aspose_Imaging_Font_Aspose_Imaging_Brush_System_Single_System_Single_Aspose_Imaging_StringFormat_"></a> DrawString\(string, Font, Brush, float, float, StringFormat\)

Draws the specified text string at the specified location with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects using the formatting attributes of the specified Aspose.Imaging.StringFormat.

```csharp
public void DrawString(string s, Font font, Brush brush, float x, float y, StringFormat format)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

x float

The x-coordinate of the upper-left corner of the drawn text.

y float

The y-coordinate of the upper-left corner of the drawn text.

format StringFormat

Aspose.Imaging.StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.

Exceptions

ArgumentNullException

brush is null. -or- s is null.

DrawString(string, Font, Brush, PointF, StringFormat)

Draws the specified text string at the specified location with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects using the formatting attributes of the specified Aspose.Imaging.StringFormat.

public void DrawString(string s, Font font, Brush brush, PointF point, StringFormat format)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

point PointF

Aspose.Imaging.PointF structure that specifies the upper-left corner of the drawn text.

format StringFormat

Aspose.Imaging.StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.

Exceptions

ArgumentNullException

brush is null. -or- s is null.

DrawString(string, Font, Brush, RectangleF)

Draws the specified text string in the specified rectangle with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects.

public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

layoutRectangle RectangleF

Aspose.Imaging.RectangleF structure that specifies the location of the drawn text.

Exceptions

ArgumentNullException

brush is null. -or- s is null.

DrawString(string, Font, Brush, RectangleF, StringFormat)

Draws the specified text string in the specified rectangle with the specified Aspose.Imaging.Brush and Aspose.Imaging.Font objects using the formatting attributes of the specified Aspose.Imaging.StringFormat.

public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)

Parameters

s string

String to draw.

font Font

Aspose.Imaging.Font that defines the text format of the string.

brush Brush

Aspose.Imaging.Brush that determines the color and texture of the drawn text.

layoutRectangle RectangleF

Aspose.Imaging.RectangleF structure that specifies the location of the drawn text.

format StringFormat

Aspose.Imaging.StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.

Exceptions

ArgumentNullException

brush is null. -or- s is null. -or- brush is null.

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.

public void EndUpdate()

FillClosedCurve(Brush, PointF[])

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.PointF structures. This method uses a default tension of 0.5 and Aspose.Imaging.FillMode.Alternate fill mode.

public void FillClosedCurve(Brush brush, PointF[] points)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillClosedCurve(Brush, PointF[], FillMode)

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.PointF structures using the specified fill mode. This method uses a default tension of 0.5.

public void FillClosedCurve(Brush brush, PointF[] points, FillMode fillMode)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

fillMode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines how the curve is filled.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillClosedCurve(Brush, PointF[], FillMode, float)

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.PointF structures using the specified fill mode and tension.

public void FillClosedCurve(Brush brush, PointF[] points, FillMode fillmode, float tension)

Parameters

brush Brush

A Aspose.Imaging.Brush that determines the characteristics of the fill.

points PointF[]

Array of Aspose.Imaging.PointF structures that define the spline.

fillmode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines how the curve is filled.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillClosedCurve(Brush, Point[])

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.Point structures. This method uses a default tension of 0.5 and Aspose.Imaging.FillMode.Alternate fill mode.

public void FillClosedCurve(Brush brush, Point[] points)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillClosedCurve(Brush, Point[], FillMode)

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.Point structures using the specified fill mode. This method uses a default tension of 0.5.

public void FillClosedCurve(Brush brush, Point[] points, FillMode fillmode)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

fillmode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines how the curve is filled.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillClosedCurve(Brush, Point[], FillMode, float)

Fills the interior of a closed cardinal spline curve defined by an array of Aspose.Imaging.Point structures using the specified fill mode and tension.

public void FillClosedCurve(Brush brush, Point[] points, FillMode fillmode, float tension)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points Point[]

Array of Aspose.Imaging.Point structures that define the spline.

fillmode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines how the curve is filled.

tension float

Value greater than or equal to 0.0F that specifies the tension of the curve.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillEllipse(Brush, RectangleF)

Fills the interior of an ellipse defined by a bounding rectangle specified by a Aspose.Imaging.RectangleF structure.

public void FillEllipse(Brush brush, RectangleF rect)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect RectangleF

Aspose.Imaging.RectangleF structure that represents the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

brush is null.

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.

public void FillEllipse(Brush brush, float x, float y, float width, float height)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x float

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

y float

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

width float

Width of the bounding rectangle that defines the ellipse.

height float

Height of the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

brush is null.

FillEllipse(Brush, Rectangle)

Fills the interior of an ellipse defined by a bounding rectangle specified by a Aspose.Imaging.Rectangle structure.

public void FillEllipse(Brush brush, Rectangle rect)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect Rectangle

Aspose.Imaging.Rectangle structure that represents the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

brush is null.

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.

public void FillEllipse(Brush brush, int x, int y, int width, int height)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x int

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

y int

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.

width int

Width of the bounding rectangle that defines the ellipse.

height int

Height of the bounding rectangle that defines the ellipse.

Exceptions

ArgumentNullException

brush is null.

FillPath(Brush, GraphicsPath)

Fills the interior of a Aspose.Imaging.GraphicsPath.

public void FillPath(Brush brush, GraphicsPath path)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

path GraphicsPath

Aspose.Imaging.GraphicsPath that represents the path to fill.

Exceptions

ArgumentNullException

brush is null. -or- path is null.

FillPie(Brush, Rectangle, float, float)

Fills the interior of a pie section defined by an ellipse specified by a Aspose.Imaging.RectangleF structure and two radial lines.

public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect Rectangle

Aspose.Imaging.Rectangle structure that represents the bounding rectangle that defines the ellipse from which the pie section comes.

startAngle float

Angle in degrees measured clockwise from the x-axis to the first side of the pie section.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to the second side of the pie section.

Examples

The following example shows how to compose an animated GIF image from individual GIF blocks.```csharp [C#]

                                                                                                   string dir = "c:\\temp\\";

                                                                                                   // Create a GIF image 100 x 100 px.
                                                                                                   // The first block is fully black by default.
                                                                                                   using (Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock firstBlock = new Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock(100, 100))
                                                                                                   using (Aspose.Imaging.FileFormats.Gif.GifImage gifImage = new Aspose.Imaging.FileFormats.Gif.GifImage(firstBlock))
                                                                                                   {
                                                                                                       // The first circle is red
                                                                                                       Aspose.Imaging.Brushes.SolidBrush brush1 = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);

                                                                                                       // The second circle is black
                                                                                                       Aspose.Imaging.Brushes.SolidBrush brush2 = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Black);

                                                                                                       // Gradually inscrease the angle of the red arc shape.
                                                                                                       for (int angle = 10; angle &lt;= 360; angle += 10)
                                                                                                       {
                                                                                                           Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock block = new Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock(100, 100);

                                                                                                           Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(block);
                                                                                                           gr.FillPie(brush1, block.Bounds, 0, angle);

                                                                                                           gifImage.AddBlock(block);
                                                                                                       }

                                                                                                       // Gradually inscrease the angle of the black arc and wipe out the red arc.
                                                                                                       for (int angle = 10; angle &lt;= 360; angle += 10)
                                                                                                       {
                                                                                                           Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock block = new Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock(100, 100);

                                                                                                           Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(block);
                                                                                                           gr.FillPie(brush2, block.Bounds, 0, angle);
                                                                                                           gr.FillPie(brush1, block.Bounds, angle, 360 - angle);

                                                                                                           gifImage.AddBlock(block);
                                                                                                       }

                                                                                                       gifImage.Save(dir + "animated_radar.gif");
                                                                                                   }

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

<code class="paramref">brush</code> is null.

### <a id="Aspose_Imaging_Graphics_FillPie_Aspose_Imaging_Brush_Aspose_Imaging_RectangleF_System_Single_System_Single_"></a> FillPie\(Brush, RectangleF, float, float\)

Fills the interior of a pie section defined by an ellipse specified by a Aspose.Imaging.RectangleF structure and two radial lines.

```csharp
public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect RectangleF

Aspose.Imaging.RectangleF structure that represents the bounding rectangle that defines the ellipse from which the pie section comes.

startAngle float

Angle in degrees measured clockwise from the x-axis to the first side of the pie section.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to the second side of the pie section.

Exceptions

ArgumentNullException

brush is null.

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.

public void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x float

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie section comes.

y float

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie section comes.

width float

Width of the bounding rectangle that defines the ellipse from which the pie section comes.

height float

Height of the bounding rectangle that defines the ellipse from which the pie section comes.

startAngle float

Angle in degrees measured clockwise from the x-axis to the first side of the pie section.

sweepAngle float

Angle in degrees measured clockwise from the startAngle parameter to the second side of the pie section.

Exceptions

ArgumentNullException

brush is null.

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.

public void FillPie(Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x int

The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie section comes.

y int

The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the pie section comes.

width int

Width of the bounding rectangle that defines the ellipse from which the pie section comes.

height int

Height of the bounding rectangle that defines the ellipse from which the pie section comes.

startAngle int

Angle in degrees measured clockwise from the x-axis to the first side of the pie section.

sweepAngle int

Angle in degrees measured clockwise from the startAngle parameter to the second side of the pie section.

Exceptions

ArgumentNullException

brush is null.

FillPolygon(Brush, PointF[])

Fills the interior of a polygon defined by an array of points specified by Aspose.Imaging.PointF structures and Aspose.Imaging.FillMode.Alternate.

public void FillPolygon(Brush brush, PointF[] points)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the vertices of the polygon to fill.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillPolygon(Brush, PointF[], FillMode)

Fills the interior of a polygon defined by an array of points specified by Aspose.Imaging.PointF structures using the specified fill mode.

public void FillPolygon(Brush brush, PointF[] points, FillMode fillMode)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points PointF[]

Array of Aspose.Imaging.PointF structures that represent the vertices of the polygon to fill.

fillMode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines the style of the fill.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillPolygon(Brush, Point[])

Fills the interior of a polygon defined by an array of points specified by Aspose.Imaging.Point structures and Aspose.Imaging.FillMode.Alternate.

public void FillPolygon(Brush brush, Point[] points)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points Point[]

Array of Aspose.Imaging.Point structures that represent the vertices of the polygon to fill.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillPolygon(Brush, Point[], FillMode)

Fills the interior of a polygon defined by an array of points specified by Aspose.Imaging.Point structures using the specified fill mode.

public void FillPolygon(Brush brush, Point[] points, FillMode fillMode)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

points Point[]

Array of Aspose.Imaging.Point structures that represent the vertices of the polygon to fill.

fillMode FillMode

Member of the Aspose.Imaging.FillMode enumeration that determines the style of the fill.

Exceptions

ArgumentNullException

brush is null. -or- points is null.

FillRectangle(Brush, Rectangle)

Fills the interior of a rectangle specified by a Aspose.Imaging.Rectangle structure.

public void FillRectangle(Brush brush, Rectangle rect)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect Rectangle

Aspose.Imaging.Rectangle structure that represents the rectangle to fill.

Exceptions

ArgumentNullException

brush is null.

FillRectangle(Brush, RectangleF)

Fills the interior of a rectangle specified by a Aspose.Imaging.RectangleF structure.

public void FillRectangle(Brush brush, RectangleF rect)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rect RectangleF

Aspose.Imaging.RectangleF structure that represents the rectangle to fill.

Exceptions

ArgumentNullException

brush is null.

FillRectangle(Brush, float, float, float, float)

Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.

public void FillRectangle(Brush brush, float x, float y, float width, float height)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x float

The x-coordinate of the upper-left corner of the rectangle to fill.

y float

The y-coordinate of the upper-left corner of the rectangle to fill.

width float

Width of the rectangle to fill.

height float

Height of the rectangle to fill.

Exceptions

ArgumentNullException

brush is null.

FillRectangle(Brush, int, int, int, int)

Fills the interior of a rectangle specified by a pair of coordinates, a width and a height.

public void FillRectangle(Brush brush, int x, int y, int width, int height)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

x int

The x-coordinate of the upper-left corner of the rectangle to fill.

y int

The y-coordinate of the upper-left corner of the rectangle to fill.

width int

Width of the rectangle to fill.

height int

Height of the rectangle to fill.

Exceptions

ArgumentNullException

brush is null.

FillRectangles(Brush, Rectangle[])

Fills the interiors of a series of rectangles specified by Aspose.Imaging.Rectangle structures.

public void FillRectangles(Brush brush, Rectangle[] rects)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rects Rectangle[]

Array of Aspose.Imaging.Rectangle structures that represent the rectangles to fill.

Exceptions

ArgumentNullException

brush is null or rects is null.

FillRectangles(Brush, RectangleF[])

Fills the interiors of a series of rectangles specified by Aspose.Imaging.RectangleF structures.

public void FillRectangles(Brush brush, RectangleF[] rects)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

rects RectangleF[]

Array of Aspose.Imaging.Rectangle structures that represent the rectangles to fill.

Exceptions

ArgumentNullException

brush is null or rects is null.

FillRegion(Brush, Region)

Fills the interior of a Aspose.Imaging.Region.

public void FillRegion(Brush brush, Region region)

Parameters

brush Brush

Aspose.Imaging.Brush that determines the characteristics of the fill.

region Region

Aspose.Imaging.Region that represents the area to fill.

Exceptions

ArgumentNullException

brush is null. -or- region is null.

~Graphics()

protected ~Graphics()

MeasureString(string, Font, SizeF, StringFormat)

Measures the specified text string with specified parameters

public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat)

Parameters

text string

The text to measure.

font Font

The font to measure.

layoutArea SizeF

The layout area.

stringFormat StringFormat

The string format.

Returns

SizeF

Size in pixels of measured text string

MultiplyTransform(Matrix)

Multiplies the Aspose.Imaging.Matrix that represents the local geometric transform of this Aspose.Imaging.Graphics by the specified Aspose.Imaging.Matrix by prepending the specified Aspose.Imaging.Matrix.

public void MultiplyTransform(Matrix matrix)

Parameters

matrix Matrix

The Aspose.Imaging.Matrix by which to multiply the geometric transform.

MultiplyTransform(Matrix, MatrixOrder)

Multiplies the Aspose.Imaging.Matrix that represents the local geometric transform of this Aspose.Imaging.Graphics by the specified Aspose.Imaging.Matrix in the specified order.

public void MultiplyTransform(Matrix matrix, MatrixOrder order)

Parameters

matrix Matrix

The Aspose.Imaging.Matrix by which to multiply the geometric transform.

order MatrixOrder

A Aspose.Imaging.MatrixOrder that specifies in which order to multiply the two matrices.

ResetTransform()

Resets the Aspose.Imaging.Graphics.Transform property to identity.

public void ResetTransform()

RotateTransform(float)

Rotates the local geometric transform by the specified amount. This method prepends the rotation to the transform.

public void RotateTransform(float angle)

Parameters

angle float

The angle of rotation.

RotateTransform(float, MatrixOrder)

Rotates the local geometric transform by the specified amount in the specified order.

public void RotateTransform(float angle, MatrixOrder order)

Parameters

angle float

The angle of rotation.

order MatrixOrder

A Aspose.Imaging.MatrixOrder that specifies whether to append or prepend the rotation matrix.

ScaleTransform(float, float)

Scales the local geometric transform by the specified amounts. This method prepends the scaling matrix to the transform.

public void ScaleTransform(float sx, float sy)

Parameters

sx float

The amount by which to scale the transform in the x-axis direction.

sy float

The amount by which to scale the transform in the y-axis direction.

ScaleTransform(float, float, MatrixOrder)

Scales the local geometric transform by the specified amounts in the specified order.

public void ScaleTransform(float sx, float sy, MatrixOrder order)

Parameters

sx float

The amount by which to scale the transform in the x-axis direction.

sy float

The amount by which to scale the transform in the y-axis direction.

order MatrixOrder

A Aspose.Imaging.MatrixOrder that specifies whether to append or prepend the scaling matrix.

TranslateTransform(float, float)

Translates the local geometric transform by the specified dimensions. This method prepends the translation to the transform.

public void TranslateTransform(float dx, float dy)

Parameters

dx float

The value of the translation in x.

dy float

The value of the translation in y.

TranslateTransform(float, float, MatrixOrder)

Translates the local geometric transform by the specified dimensions in the specified order.

public void TranslateTransform(float dx, float dy, MatrixOrder order)

Parameters

dx float

The value of the translation in x.

dy float

The value of the translation in y.

order MatrixOrder

The order (prepend or append) in which to apply the translation.