How to Draw Shapes in C#

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#

  1. Install Aspose.Drawing for .NET package from NuGet.org
  2. Include Aspose.Drawing and System.Drawing namespaces
  3. Apply license to Aspose.Drawing for .NET to avoid evaluation watermark
  4. Create a Bitmap object of required dimensions
  5. Create a Graphics object from the Bitmap object created above
  6. Create a new Pen tool object with required color and thickness
  7. Use DrawEllipse method to draw an ellipse on the image
  8. 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.

 English