I need to serialize a color used in a WPF application to a database. I’d like to use the sRGB values, because they’re more familiar to those of us that have spent the last few years doing web development.
How can a get an ARGB string (like #FFFFFFFF) from a System.Windows.Media.Color object?
UPDATE: I was misled by the documentation on MSDN. As @Kris noted below, the documentation for the ToString() method is incorrect. Although it says that ToString() “creates a string representation of the color using the ScRGB channels”, it will actually return a string in ARGB hex format if the color was created using the FromARGB() method. It’s an undocumented feature, I suppose.
If you create your colors using either Color.FromRgb or Color.FromArgb instead of FromScRgb you should get a hex string result from ToString.
If you want to do it manually
You can use int.Parse(,NumberStyles.HexNumber) to go the other way.
Note sRGB and scRGB refer to different color spaces, make sure your using the one you want.