public static byte[] GetBytes(Color color, ColorType type)
{
switch (type)
{
case ColorType.ARGB8888_32:
return ByteConverter.GetBytes(color.ToArgb());
case ColorType.XRGB8888_32:
color = Color.FromArgb(0, color);
goto case ColorType.ARGB8888_32;
case ColorType.ARGB8888_16:
{
byte[] result = new byte[4];
int i = color.ToArgb();
ByteConverter.GetBytes((ushort)(i & 0xFFFF)).CopyTo(result, 0);
ByteConverter.GetBytes((ushort)((i >> 16) & 0xFFFF)).CopyTo(result, 2);
return result;
}
case ColorType.XRGB8888_16:
color = Color.FromArgb(0, color);
goto case ColorType.ARGB8888_16;
case ColorType.ARGB4444:
return ByteConverter.GetBytes((ushort)(((color.A >> 4) << 12) | ((color.R >> 4) << 8) | ((color.G >> 4) << 4) | (color.B >> 4)));
case ColorType.RGB565:
return ByteConverter.GetBytes((ushort)(((color.R >> 3) << 11) | ((color.G >> 2) << 5) | (color.B >> 3)));
}
throw new ArgumentOutOfRangeException("type");
}