以下のコードでエラーが表示されます。「インデックスが配列の範囲外です」私のアルゴリズムは、配列dimention '16'、 のColorset配列を作成しますが、私は2番目の 'colorSetLegend'の寸法が必要です。以下カラー配列を別のカラー配列に設定する方法は?
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
Marcの推測のような音が当時だった。私の編集された答えを見てください。 –