我下面的代码给了我错误:“索引超出了数组的范围。”我的算法创建的颜色数组的数组维度'16', 但我需要第二个'colorSetLegend'尺寸:32如果你看下面的粗体代码,返回我的错误。如何将颜色数组设置为另一个颜色数组?
Color[] colorSetLegend = new Color[32];
Color[] colorSet = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
Color end = Color.White;
colorSet = ColorMaker.GenerateColor(colorSet, end);
for (int i = 0; i < colorSet.Length;)
{
for (int j = 0; j < colorSetLegend.Length;)
{
colorSetLegend[j] = colorSet[i];
colorSetLegend[j++] = Color.Black;
i++;
}
}
我的色彩以下发电机:
public class ColorMaker
{
public static Color[] GenerateColor(Color[] baseColorSet, Color end)
{
Color[] colorSet = new Color[16];
int j = 0;
foreach (Color start in baseColorSet)
{
for (int i = 0; i < 15; i += 4)
{
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);
colorSet[j] = Color.FromArgb(r, g, b);
j++;
}
}
return colorSet;
}
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;
}
}
ForExample; colorSetLegend [0] =“红色”; colorSetLegend [1] = Color.Black; colorSetLegend [2] =“FireBrick”; colorSetLegend [3] = Color.Black; – Penguen 2009-06-16 13:49:42
听起来像马克的猜测是正确的。看看我编辑的答案。 – 2009-06-16 13:52:07