Draw a Circle in C#

Drawing shapes in C# is a common task, and drawing circles is one of the most basic shapes. Learn how to draw a circle in C#. In this blog post, we will also show you how to fill in the circle with a color programmatically using C#.

This article covers the following topics:

  1. C# Graphics API to Draw a Circle
  2. Draw a Circle in C#
  3. Draw a Filled Circle in C#
  4. Circle with Border in C#
  5. Free Learning Resources

C# Graphics API to Draw a Circle

We will use Aspose.Drawing for .NET to draw a circle in C#. It is a fully managed, cross-platform, complete 2D graphics library for drawing text, geometries, and images. It offers a wide range of image manipulation operations, including cropping, resizing, rotating, flipping, and watermarking. This makes it an ideal choice for developers who need to create and edit images in their applications.

Please download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Drawing

Draw a Circle in C#

We can easily draw a circle by following the steps below:

  1. Create an instance of the Bitmap class.
  2. Create a new Graphics object from the Bitmap object using the FromImage() method.
  3. Initialize a Pen class object with the specified color and size.
  4. After that, call the DrawEllipse() method to draw a circle with a specified size.
  5. Finally, save the output image using the Save() method.

The following code sample shows how to draw a circle in C#.

Draw a Circle in C#

Draw a Circle in C#

Draw a Filled Circle in C#

Similarly, we can draw a filled circle by following the steps below:

  1. Create an instance of the Bitmap class.
  2. Create a new Graphics object from the Bitmap object using the FromImage() method.
  3. Initialize a SolidBrush class object with the specified color.
  4. After that, call the FillEllipse() method to draw a filled circle.
  5. Finally, save the output image using the Save() method.

The following code sample shows how to draw a filled circle in C#.

Draw a Filled Circle in C#

Draw a Filled Circle in C#

Draw a Circle with a Border in C#

We can also draw a filled circle with broder by following the steps mentioned earlier. We will create two circles: the outer circle for the border and the inner filled circle.

The following code sample shows how to draw a circle with a border in C#.

Draw a Circle with a Border in C#

Draw a Circle with a Border in C#

Get a Free License

You can get a free temporary license to evaluate the API in its full capacity.

C# Draw Circle – Free Learning Resources

You can learn more about drawing basic shapes and explore various other features of the library using the resources below:

Conclusion

In this article, we have learned how to draw a cricle in C#. We have also seen how to draw a filled circle and set its border programmatically using Aspose.Drawing for .NET. By leveraging Aspose.Drawing, you can also render vector graphics such as lines, curves, and figures, as well as text in a variety of fonts, sizes, and styles, onto raster images. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also