Draw Ellipse C#

Vector graphics are widely used to draw shapes. You can easily draw shapes in C# applications while working with Aspose.Drawing API. In accordance with such requirements, this article covers how to draw Ellipse in C#.

Create Ellipse Shape - C# API Installation

You need to install Aspose.Drawing for .NET API. Simply configure it from the Downloads section or use the following NuGet command in Microsoft Visual Studio IDE:

PM> Install-Package Aspose.Drawing

Draw an Ellipse in C#

You can draw an ellipse by following the steps below:

  • Initialize a Bitmap class object
  • Create a Pen class instance
  • Draw the ellipse
  • Save output drawing image

The following code snippet explains how to draw an ellipse in C#:

// Initialize a Bitmap class object
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics graphics = Graphics.FromImage(bitmap);
// Create a Pen class instance
Pen pen = new Pen(Color.FromKnownColor(KnownColor.Blue), 2);
// Draw the ellipse
graphics.DrawEllipse(pen, 10, 10, 900, 700);
// Save output drawing image
bitmap.Save("DrawEllipse.png");
view raw draw-ellipse.cs hosted with ❤ by GitHub

Draw an Ellipse in C# - Advanced

You can set up different properties while drawing an ellipse. For instance, you can use solid brush or texture brush to draw the ellipse. The following steps show advanced rendering of an ellipse drawing:

  • Initialize a Bitmap class object
  • Create a brush while specifying its color
  • Create a Pen using the brush
  • Draw the ellipse
  • Save output drawing image

The code snippet below explains how to draw an ellipse with advanced options in C#:

// Initialize a Bitmap class object
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
// Create graphics class instance
Graphics graphics = Graphics.FromImage(bitmap);
// Create a brush while specifying its color
Brush brush = new SolidBrush(Color.FromKnownColor(KnownColor.Blue));
// Create a pen
Pen pen = new Pen(brush);
// Draw Ellipse
graphics.DrawEllipse(pen, 10, 10, 900, 700);
// Save output drawing
bitmap.Save("DrawEllipse.png");

Get Free Temporary License

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

Conclusion

In this article, you have learned how to draw an ellipse with different options programmatically in C#. Moreover, you may visit the documentation section to learn more details about the features offered by the API. In case of any concerns, please write to us at the forum.

See Also

Using System.Drawing with .NET 6 on a non-Windows Platform