gpt4 book ai didi

C#填充多边形(三角形)

转载 作者:太空宇宙 更新时间:2023-11-03 10:50:16 29 4
gpt4 key购买 nike

我在绘制两个多边形时遇到问题。我想填充两个三角形,但一个大于第二个。我在 winforms 中使用 UserControl。代码:

Point[] DOWN = new Point[] {new Point(0, 0), new Point(10, 0), new Point(5, 5)};
Point[] UP = new Point[] { new Point(0, 15), new Point(10, 15), new Point(5, 10) };

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19));
e.Graphics.FillPolygon(brush, DOWN);
e.Graphics.FillPolygon(brush, UP);
brush.Dispose();
}

This is result of fill polygons问题出在哪里?

最佳答案

尝试设置 PixelOffsetMode 属性:

e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
using (SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19))) {
e.Graphics.FillPolygon(brush, DOWN);
e.Graphics.FillPolygon(brush, UP);
}

结果:

enter image description here

关于C#填充多边形(三角形),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21684873/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com