Working with Vector Graphics in C#
Contents
[
Hide
]
Aspose.Drawing for .NET makes it easy for you to draw vector graphics using C#. The API lets you work with a variety of different vector graphics such as arcs, Bezier spline, Cardinal Spline, closed curves, ellipses, lines and a number of other types. This article contains C# examples for drawing different types of vector graphics using the API.
Draw Arc in C#
To drawn an arc using C#:
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawArc method of Graphics class object to draw an arc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawArc(pen, 0, 0, 700, 700, 0, 180); | |
bitmap.Save("DrawArc.png"); |

Draw Bezier Spline in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawBezier method of Graphics class object to draw Bezier Spline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
PointF p1 = new PointF(0, 0); // start point | |
PointF c1 = new PointF(0, 800); // first control point | |
PointF c2 = new PointF(1000, 0); // second control point | |
PointF p2 = new PointF(1000, 800); // end point | |
graphics.DrawBezier(pen, p1, c1, c2, p2); | |
bitmap.Save("DrawBezierSpline.png"); |

Draw Cardinal Spline in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawCurve method of Graphics class object to draw Cardinal Spline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawCurve(pen, new Point[] { new Point(10, 700), new Point(250, 500), new Point(500, 10), new Point(750, 500), new Point(990, 700) }); | |
bitmap.Save("DrawCardinalSpline.png"); |

Draw Closed Curve in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawClosedCurve method of Graphics class object to draw closed curve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawClosedCurve(pen, new Point[] { new Point(100, 700), new Point(350, 600), new Point(500, 500), new Point(650, 600), new Point(900, 700) }); | |
bitmap.Save("DrawClosedCurve.png"); |

Draw Ellipse in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawEllipse method of Graphics class object to draw Ellipse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawEllipse(pen, 10, 10, 900, 700); | |
bitmap.Save("DrawEllipse.png"); |

Draw Lines in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawLine method of Graphics class object to draw lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawLine(pen, 10, 700, 500, 10); | |
graphics.DrawLine(pen, 500, 10, 990, 700); | |
bitmap.Save("DrawLines.png"); |

Draw Path in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Initialize a new object of GraphicsPath class and add Lines to its path collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
using System.Drawing.Drawing2D; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
GraphicsPath path = new GraphicsPath(); | |
path.AddLine(100, 100, 1000, 400); | |
path.AddLine(1000, 600, 300, 600); | |
path.AddRectangle(new Rectangle(500, 350, 200, 400)); | |
path.AddEllipse(10, 250, 450, 300); | |
graphics.DrawPath(pen, path); | |
bitmap.Save("DrawPath.png"); |

Draw Polygon in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawPolygon method of Graphics class object to draw Polygon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawPolygon(pen, new Point[] { new Point(100, 100), new Point(500, 700), new Point(900, 100) }); | |
bitmap.Save("DrawPolygon.png"); |

Draw Rectangle in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawRectangle method of Graphics class object to draw Rectangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawRectangle(pen, 10, 10, 900, 700); | |
bitmap.Save("DrawRectangle.png"); |

Fill Region in C#
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Instantiate a GraphicsPath class object
- Add polygon to the Path collection of GraphicsPath class object
- Use the FillRegion method of Graphics class to fill defined regions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
using System.Drawing.Drawing2D; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
GraphicsPath path = new GraphicsPath(); | |
path.AddPolygon(new Point[] { new Point(100, 400), new Point(500, 100), new Point(900, 400), new Point(500, 700) }); | |
Region region = new Region(path); | |
GraphicsPath innerPath = new GraphicsPath(); | |
innerPath.AddRectangle(new Rectangle(300, 300, 400, 200)); | |
region.Exclude(innerPath); | |
Brush brush = new SolidBrush(Color.Blue); | |
graphics.FillRegion(brush, region); | |
bitmap.Save("FillRegion.png"); |
