【发布时间】:2009-06-12 12:21:00
【问题描述】:
如何生成 16 色。我的起始颜色是“红色”,我的终端颜色是“卡其色”。我必须插入 14 种颜色。但它看起来像梯度流。例如 color.Black 不是来自红色。暴力应该由红变红。
【问题讨论】:
如何生成 16 色。我的起始颜色是“红色”,我的终端颜色是“卡其色”。我必须插入 14 种颜色。但它看起来像梯度流。例如 color.Black 不是来自红色。暴力应该由红变红。
【问题讨论】:
你应该能够插值?这个例子是winforms,但数学是相同的——只是使用ASP.NET,你必须以十六进制形式编写颜色。您可能还(使用 ASP.NET)需要单独查找 RGB 值 - 但对于信息,卡其色(在 winforms 中)是 {240,230,140}(红色显然是 {255,0,0})。
using System.Drawing;
using System.Windows.Forms;
static class Program {
static void Main()
{
Form form = new Form();
Color start = Color.Red, end = Color.Khaki;
for (int i = 0; i < 16; i++)
{
int r = Interpolate(start.R, end.R, 15, i),
g = Interpolate(start.G, end.G, 15, i),
b = Interpolate(start.B, end.B, 15, i);
Button button = new Button();
button.Dock = DockStyle.Top;
button.BackColor = Color.FromArgb(r, g, b);
form.Controls.Add(button);
button.BringToFront();
}
Application.Run(form);
}
static int Interpolate(int start, int end, int steps, int count)
{
float s = start, e = end, final = s + (((e - s) / steps) * count);
return (int)final;
}
}
【讨论】: