Skip to content Skip to sidebar Skip to footer

Convert Color Integer To Text?

I need to convert a color integer value back to text? For example, look at this imaginative code int myColor = -16777216; //int value for Color.BLACK convertColorToText(myColor);

Solution 1:

I don't think you can do it out-of-the-box, best what you can do is to build a map or list of known colors (for example using 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray' -> standard android colors understood by parseColor method http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

And then you could find it by lookup and either exact match (but the usefulness of this would be limited) or finding the CLOSEST color. You can find out about a good and simplest algorithm of finding best match here, for example: Best algorithm for matching colours.

Post a Comment for "Convert Color Integer To Text?"