简体   繁体   English

在Java中获取十六进制颜色的名称?

[英]Get the name of a hexadecimal colour in Java?

Should be a straightforward question, say I have something like this: 应该是一个简单的问题,说我有这样的事情:

int pink = 0xff00ff;

How can I convert this integer to find out what colour it is? 如何转换此整数以找出它是什么颜色? So basically an algorithm of some sort that will take a colour and print out it's name. 所以基本上是某种类型的算法,它会采用颜色并打印出它的名字。 It doesn't matter if it's a light or dark pink, it just needs to tell me that it is pink. 如果它是浅粉色或深粉色并不重要,它只需要告诉我它是粉红色的。 Is this possible? 这可能吗? I'm using Java, if this helps. 我正在使用Java,如果这有帮助的话。

edit: Also, I don't mind if I have to use a library. 编辑:另外,我不介意我是否必须使用库。

Unless their is an existing library, you might have to create the list of colours and get the closest value. 除非它们是现有库,否则您可能必须创建颜色列表并获得最接近的值。

I think this is the good source to get started: 我认为这是开始的好来源:

https://gist.github.com/XiaoxiaoLi/8031146 https://gist.github.com/XiaoxiaoLi/8031146

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM