作者:劲朋_511 | 来源:互联网 | 2023-02-05 22:55
直接使用等比例抽样算法,连同透明度一起计算。1publicIList<Color>ShadeColors(Colorc1
直接使用等比例抽样算法,连同透明度一起计算。
1 public IList ShadeColors(Color c1, Color c2, int resultCount)
2 {
3 var result = new List();
4 for (int i = 0; i )
5 {
6 var a = c1.A + (int)((c2.A - c1.A) * i / resultCount);
7 var r = c1.R + (int)((c2.R - c1.R) * i / resultCount);
8 var g = c1.G + (int)((c2.G - c1.G) * i / resultCount);
9 var b = c1.B + (int)((c2.B - c1.B) * i / resultCount);
10 var c = Color.FromArgb(a, r, g, b);
11 result.Add(c);
12 }
13 return result;
14 }
输出图片
如果要输出图片可能需要安装libgdiplus
,如果缺少依赖的话, 详见CoreCompat/CoreCompat。在Ubuntu
执行命令:
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
输出图片的代码:
1 static void Main(string[] args)
2 {
3 int size = 300;
4 int h = 30;
5 var bmp = new Bitmap(size, h, PixelFormat.Format32bppArgb);
6 Color c1 = Color.FromArgb(0xff, Color.Green);
7 Color c2 = Color.FromArgb(0x4e, Color.Yellow);
8 var cs = ShadeColors(c1, c2, size);
9 for (int i = 0; i )
10 {
11 for (int j = 0; j )
12 {
13 bmp.SetPixel(i, j, cs[i]);
14 }
15 }
16 bmp.Save("shade.png", ImageFormat.Png);
17 Console.WriteLine("Hello World!");
18 // Console.ReadLine();
19 }
最终输出的图片