I know how to convert a string to an XNA Color object, but how do I convert a C# Color object like Color.Blue into its string representation(e.g. “Blue”).
I know how to convert a string to an XNA Color object , but
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to do the reverse of what was done in your previous question:
e.g.
Note: This will give you an empty string if the color name isn’t known.
[EDIT]
You might want to try using a TypeConverter here. I’m not sure that one exists for the XNA Color type, but it’s worth a shot:
[EDIT]
Since none of the above is going to do what you want, you’ll have to try a similar approach to what Jon has done here: Convert string to Color in C#
You’ll need to pull all the XNA colors into a dictionary using reflection, like he has done, but reverse the keys and values, so it’s Dictionary, then write a function that accesses the dictionary taking a Color parameter and returning the name.