将十六进制颜色代码转换为颜色名称 [英] Convert hex color code to color name
本文介绍了将十六进制颜色代码转换为颜色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将颜色的十六进制表示形式转换为相应的名称?
How can I translate a hex representation of a color to its corresponding name?
例如,考虑以下颜色:
rainbow(4)
# "#FF0000FF" "#80FF00FF" "#00FFFFFF" "#8000FFFF"
他们叫什么名字(希望每个代码都有一个名字)?
What are their names (hoping a name exist for each code)?
我发现了函数 col2rgb()
,但是它不能满足我的需要。
I discovered the function col2rgb()
but it does not exaclty what I am needing.
推荐答案
您可以使用<的便捷功能 color.id
code> plotrix 包*:
You may use the convenience function color.id
from the plotrix
package*:
给出指定为十六进制字符串的颜色,找到最接近的颜色
Given a color specified as a hex string, find the closest match in the table of known (named) colors.
library(plotrix)
sapply(rainbow(4), color.id)
# $`#FF0000FF`
# [1] "red" "red1"
#
# $`#80FF00FF`
# [1] "chartreuse" "chartreuse1"
#
# $`#00FFFFFF`
# [1] "cyan" "cyan1"
#
# $`#8000FFFF`
# [1] "purple"
*在此归功于Jim Lemon及其答案:将颜色十六进制代码转换为颜色名称。
这篇关于将十六进制颜色代码转换为颜色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文