This step by step tutorial elaborates how to draw shapes in C#. Aspose.Drawing for .NET is a C# vector graphics library which lets you draw shapes in C#. You can not only draw circle in C#, but also draw ellipse, arc, rectangle, and polygon shapes.
Steps to Draw Shapes in C#
- Install Aspose.Drawing for .NET package from NuGet.org
- Include Aspose.Drawing and System.Drawing namespaces
- Apply license to Aspose.Drawing for .NET to avoid evaluation watermark
- Create a Bitmap object of required dimensions
- Create a Graphics object from the Bitmap object created above
- Create a new Pen tool object with required color and thickness
- Use DrawEllipse method to draw an ellipse on the image
- Finally, Save the image as a PNG file
The steps given above are same for any type of vector shape you want to draw in your C# code. In this tutorial, we have used DrawEllipse method to draw ellipse in C#. However, we have specified equal size for width and height, which gives you an output as you draw circle in C#.
Code to Draw Shapes in C#
Just like the above code, you can simply use a different draw method to draw other vector shapes like an Arc, Rectangle, Polygon or others. Nothing else need to be changed. Hopefully, this draw ellipse C# code would be useful to get started in drawing vector shapes in your C# .NET applications.
The System.Drawing namespace used above is part of the Aspose.Drawing API, and it supports all the platforms seamlessly. This helps make the API work perfectly where you have been using standard .NET System.Drawing, but you want to support other platforms as well.