我下面的代碼給了我錯誤:「索引超出了數組的範圍。」我的算法創建的顏色數組的數組維度'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