转换色彩整数文本? [英] Convert color integer to text?

查看:88
本文介绍了转换色彩整数文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个彩色整数值转换为文本?例如,看一下这个富有想象力的code

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);

该方法将返回字符串值BLACK。

The method would return string with value "BLACK".

这是可能的,怎么办呢?

Is this possible and how to do it?

更新

我的应用程序使用颜色选择器(code.google.com / P / Android的颜色选择器),我想通知颜色已经选择了他哪个用户。例如,他选择黑色,点击确定按钮,看到一个吐司说:你选择了黑色。

My app uses a Color Picker (code.google.com/p/android-color-picker) and I want to notify user which color has he chosen. For example, he chooses a black color, clicks OK button, and sees a Toast saying "You have chosen Black color".

推荐答案

我不认为你可以做到这一点外的开箱,最好你可以做的是建立一个地图或已知的颜色列表(例如,使用红,蓝,绿,黑,白,灰色,青色,洋红,黄,浅灰色,深灰 - >标准Android通过parseColor方法<一个了解颜色href=\"http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String\" rel=\"nofollow\">http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

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.

这篇关于转换色彩整数文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆