public FillEllipse ( |
||
brush | ||
rect | ||
return | void |
// Create a new bitmap object and fill it with white color Bitmap bitmap = new Bitmap(200, 200); Graphics graphics = Graphics.FromImage(bitmap); graphics.Clear(Color.White); // Define an ellipse bounds Rectangle ellipseBounds = new Rectangle(50,50,100,100); // Create a new brush to fill the ellipse with red color SolidBrush brush = new SolidBrush(Color.Red); // Fill the ellipse with the brush graphics.FillEllipse(brush, ellipseBounds); // Save the bitmap to a file bitmap.Save("Ellipse.png");
// Create a new bitmap object and fill it with white color Bitmap bitmap = new Bitmap(200, 200); Graphics graphics = Graphics.FromImage(bitmap); graphics.Clear(Color.White); // Define an ellipse bounds Rectangle ellipseBounds = new Rectangle(50,50,100,100); // Create a new brush to fill the ellipse with gradient color LinearGradientBrush brush = new LinearGradientBrush(ellipseBounds, Color.Red, Color.Yellow, LinearGradientMode.ForwardDiagonal); // Fill the ellipse with the brush graphics.FillEllipse(brush, ellipseBounds); // Save the bitmap to a file bitmap.Save("GradientEllipse.png");This code draws an ellipse that is filled with a gradient color from red to yellow. This example demonstrates the use of LinearGradientBrush class from the System.Drawing package. In conclusion, System.Drawing is a powerful package library in C# that provides a range of classes for creating high-quality graphics and images. The Graphics class in the package provides the FillEllipse method to draw a solid ellipse. The examples above demonstrate the use of SolidBrush and LinearGradientBrush to fill the ellipse with different colors.