gpt4 book ai didi

c# - 如何使用 GDI+(C#、WinForms)绘制带有路径渐变的圆弧

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

这是我想要达到的结果:

enter image description here

它应该是基于矢量的,因为它是可扩展的。

这是我尝试使用 PathGradientBrush 创建它:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

double outerRadius = 120;
double innerRadius = 110;
PointF DistanceFromCenter(PointF center, double radius, double angle)
{
double angleInRadians = angle * Math.PI / 180;
return new PointF((float)(center.X + radius * (Math.Cos(angleInRadians))),
(float)(center.Y + radius * (Math.Sin(angleInRadians))));
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
GraphicsPath path = new GraphicsPath();
Point centerPoint = new Point(this.Width / 2, this.Width / 2);
path.AddLine(this.DistanceFromCenter(centerPoint, innerRadius, 0), this.DistanceFromCenter(centerPoint, outerRadius, 0));
path.AddArc(new RectangleF(centerPoint.X - (float)outerRadius, centerPoint.Y - (float)outerRadius, (float)outerRadius * 2, (float)outerRadius * 2), 0, -180);
path.AddLine(this.DistanceFromCenter(centerPoint, outerRadius, -180), this.DistanceFromCenter(centerPoint, innerRadius, -180));
path.AddArc(new RectangleF(centerPoint.X - (float)innerRadius, centerPoint.Y - (float)innerRadius, (float)innerRadius * 2, (float)innerRadius * 2), (float)0, -(float)180);

PathGradientBrush pthGrBrush = new PathGradientBrush(path);

// Set the color at the center of the path to red.
pthGrBrush.CenterColor = Color.FromArgb(255, 255, 0, 0);

// Set the colors of the points in the array.
Color[] colors = {
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0)};

pthGrBrush.SurroundColors = colors;

// Fill the path with the path gradient brush.
g.FillPath(pthGrBrush, path);
}
}

这是我得到的结果:

enter image description here

最佳答案

如果有人正在寻找这个,这是如何实现的:link .特别感谢 Thorsten Gudera。

关于c# - 如何使用 GDI+(C#、WinForms)绘制带有路径渐变的圆弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25423830/

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