Fast copy of Color32[] array to byte[] array
I already saw, quiet similar question.
But I want to convert the color[] array to byte[]
private byte[] color2ByteArray(Color[] colors)
{
int len = colors.Length;
byte[] result = new byte[len * 3];
int index = 0;
for (int i = 0; i < len; i++)
{
result[index++] = (byte)(colors[i].r * 255);
result[index++] = (byte)(colors[i].g * 255);
result[index++] = (byte)(colors[i].b * 255);
}
return result;
}
To obtain a proper color value and convert the byte[] array. I have to multiply the color x 255.
I've seen a lot of posts about Marshal.copy
But I don't know how to change it to make it faster