How can you unpack a Color.PackedValue

c#, xna

Solution

`PackedValue` is a read/write property. You don't need to do any bit shifting to make use of it.

var c = new Color() { PackedValue = packedColor };
Console.WriteLine(c.A);
Console.WriteLine(c.R);
Console.WriteLine(c.G);
Console.WriteLine(c.B);

Problem

I am trying save a Color to a database. I know I could cut the color into 4 parts, RGBA but it seems silly to save a color using 3 columns. So then I though of simply saving it to a string using a limiter, or even just using 3 characters per color. But again it seems silly. The Color structure has an packedValue Property, which seems to do something with the values to create a uint. but I don't know how to unpack it. Anyone have any ideas ``` Color c = new Color.Black; uint i = c.PackedValue; Color newColor=Color.FromUINT(i); // This doesn't work of course ```

Original source