我有这个代码来绘制一个矩形(我正在尝试重新生成MS画图)
case "Rectangle":
if (tempDraw != null)
{
tempDraw = (Bitmap)snapshot.Clone();
Graphics g = Graphics.FromImage(tempDraw);
Pen myPen = new Pen(foreColor, lineWidth);
g.DrawRectangle(myPen, x1, y1, x2-x1, y2-y1);
myPen.Dispose();
e.Graphics.DrawImageUnscaled(tempDraw, 0, 0);
g.Dispose();
}但是,如果我想画一个圆,会发生什么变化呢?
g.DrawRectangle(myPen, x1, y1, x2-x1, y2-y1);发布于 2009-12-03 03:04:20
请尝试使用DrawEllipse方法。
发布于 2013-04-07 01:07:40
没有DrawCircle方法;请改用DrawEllipse。我有一个带有方便的图形扩展方法的静态类。以下是绘制和填充圆圈的方法。它们是DrawEllipse和FillEllipse的包装器
public static class GraphicsExtensions
{
public static void DrawCircle(this Graphics g, Pen pen,
float centerX, float centerY, float radius)
{
g.DrawEllipse(pen, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
public static void FillCircle(this Graphics g, Brush brush,
float centerX, float centerY, float radius)
{
g.FillEllipse(brush, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
}你可以这样叫他们:
g.FillCircle(myBrush, centerX, centerY, radius);
g.DrawCircle(myPen, centerX, centerY, radius);发布于 2009-12-03 03:04:07
如果你想用GDI+画一个圆,你需要使用DrawEllipse。
这里有一个例子:http://www.websupergoo.com/helpig6net/source/3-examples/9-drawgdi.htm
https://stackoverflow.com/questions/1835062
复制相似问题