C#GDI+画圆

GDI+是C#绘图的基本工具,GDI+可以很方便的绘制圆。

1、获得画布

Graphics g = pictureBox1.CreateGraphics();

2、设置画刷

Brush brush = new SolidBrush(pColors[i]);

3、绘制图形

g.FillEllipse(brush, posPoint[i].X, posPoint[i].Y, 10, 10);

4、效果优化

如果希望画出来的圆形更加圆滑,可以在画图之前加上如下代码

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

需要注意的是,以上参数实现的画圆,是通过指定圆上的四点实现画圆,若要求使用圆心半径确定一个圆,将画圆的函数改为:

g.FillEllipse(brush, posPoint[i].X-5, posPoint[i].Y-5, 10, 10);

让圆心的坐标减去半径即可。

猜你喜欢

转载自blog.csdn.net/ScapeD/article/details/85173982