I am trying to create a simple color gradient bitmap by iterating through all possible color combinations and adding each value to a list. Each individual RGB value is stored as an int array in the main list.
Problems occur for me when I am trying to add the array to my list. It overwrites all previous entries in the list, at last I end up with a list full of color arrays, all filled with the values 255. I know there must exist a better way to create a color spectrum bitmap than this rather clunky way, but I am very interested in why it behaves like this.
int[] temp = new int[3];
for (int r = 0; r < 256; r++)
{
for (int g = 0; g < 256; g++)
{
for (int b = 0; b < 256; b++)
{
temp[0] = r;
temp[1] = g;
temp[2] = b;
colors.Add(temp);
}
}
}