Draw Graphics using C#

In my previous article, I have given you an overview of our .NET Graphics API - Aspose.Drawing for .NET. Along with that, we have seen how to create images from scratch or draw graphics on existing images using C#. In this article, we’ll go one step ahead and learn how to create 2D drawings by drawing various graphical objects within the .NET applications such as ASP.NET web application, Windows application, and etc.

The following are the vector graphics that we are going to draw within our drawings using .NET Graphics API.

Before we start, make sure you have installed Aspose.Drawing for .NET within your .NET application. You can read about the installation methods in this post.

Create a Drawing from Scratch using C#

First of all, let’s have a look at how to create an empty drawing and save it as a PNG image. The steps are as simple as pie.

You can save the drawing in other image formats as well. The following code sample shows how to create a drawing from scratch using C#.

Draw an Arc in Drawing using C#

Let’s check out how to draw an arc within the drawing. The following are the steps to perform this operation.

The following code sample shows how to draw an arc in the drawing using C#.

Draw an Arc

Draw a Bezier Spline in Drawing using C#

The following are the steps to draw a bezier spline within a drawing.

The following code sample creates a Bezier Spline using C#.

Draw Bezier Spline

Add a Cardinal Spline in Drawing using C#

Use the following steps to draw a cardinal spline using our .NET Graphics API.

The following C# code sample draws a cardinal spline using Aspose.Drawing for .NET.

Draw Cardinal Spline

Add a Closed Curve in Drawing using C#

You can also draw a closed curve in the same way you have drawn the other graphical objects. The following are the steps for this.

You can draw a closed curve using the following C# code sample.

Draw Closed Curve

Draw an Ellipse in a Drawing using C#

The following are the steps to draw an ellipse in a drawing using Aspose.Drawing for .NET.

The following code sample shows how to draw an ellipse using C#.

Draw Ellipse

Draw Lines in a Drawing using C#

Lines are one of the basic objects for creating the drawings. The following are the steps to draw the lines in a drawing using Aspose’ Graphics API.

The following code sample shows how to draw lines within a drawing using C#.

Draw Lines

Draw a Path in the Drawing using C#

The following are the steps to draw a path within a drawing using C#.

The following code sample shows how to draw a path within a drawing using C#.

Draw Path

Draw a Polygon in a Drawing using C#

The following are the steps to draw a polygon within a drawing using Aspose.Drawing for .NET.

This is how you can draw a polygon within a drawing using C#.

Draw Polygon

Draw a Rectangle within the Drawing using C#

Last but not the least, drawing a rectangle. The following are the steps to draw a rectangle.

The following C# code sample draws a rectangle within a drawing.

Draw Rectangle

Conclusion

In this article, we have seen how various graphical objects can be drawn within a drawing programmatically using C#. The step by step guide and code samples demonstrated how to draw lines, rectangles, polygons, arcs, bezier spline, cardinal spline, curves and ellipses within the drawings. You can learn more about our .NET Graphics API using the documentation.

See Also