gpt4 book ai didi

c# - C#.NET 中的粗线绘制问题

转载 作者:太空宇宙 更新时间:2023-11-03 17:44:44 26 4
gpt4 key购买 nike

我想使用 Graphics.Lines() 方法绘制粗线。但看起来 API 有一些错误。如果您尝试使用以下代码呈现用户控件,您会得到看起来很奇怪的图像。我想知道是否有一些平滑模式或类似的东西可以解决这个线条绘制故障。

private void UserControl1_Paint(object sender, PaintEventArgs e)
{
int n = 100;
Point[] points = new Point[n];

double x = 2;
int y = 50;

for (int i = 0; i < n; i++)
{
Point p = new Point();
p.X = 200 + (int)(i * x);
p.Y = 200 + (int)(Math.Sin(i * 0.2) * y);
points[i] = p;
}

Pen pen = new Pen(new SolidBrush(Color.Blue));
//Pen pen = new Pen(new LinearGradientBrush(new Point(0, 0), new Point(0, 100), Color.Black, Color.Red));
pen.Width = 200;
e.Graphics.DrawLines(pen, points);
}

最佳答案

您会看到 GDI+ 试图在线上绘制端点的效果。这么粗的笔,那可不是好下场的。关于达芬奇用扫帚画蒙娜丽莎的想象。修复:

        Pen pen = new Pen(new SolidBrush(Color.Blue));
pen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
pen.StartCap = System.Drawing.Drawing2D.LineCap.Square;

或者改为绘制多边形,以便 GDI+ 更好地了解什么是正面和背面:

        e.Graphics.DrawPolygon(pen, points);

好吧,它看起来不再像魔鬼了。保持线宽与线中的细节成比例。

关于c# - C#.NET 中的粗线绘制问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7044288/

26 4 0
文章推荐: c# - IList 和 IBindingList 的区别
文章推荐: html - 在 div 中垂直居中链接图像
文章推荐: c# - 使用 LINQ .Select() 转换为新类型是否太慢?
文章推荐: html - 如何将