3

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.

edit: Also, I don't mind if I have to use a library.

5
  • There is no standard library to do this. You will probably need to write your own library. BTW, is 0xfd00fd also considered "pink"? Commented Sep 7, 2014 at 20:09
  • I don't think its possible, as your computer would have to guess almost all of them. For a simple version you could create a colour class and set up some static fields such as COLOUR_PINK (name field included in the class) and a .getName() function???? Commented Sep 7, 2014 at 20:10
  • Yeah 0xfd00fd is pink too, I suppose. Basically, my friend likes writing batch stuff so I was going to write a program which will take the colours from an image, guess it's colour and then spit out it's representation in batch Commented Sep 7, 2014 at 20:11
  • Loading up eclipse to try that .getName thing. Nope, just realized it would have to be a Color object for that, maybe I can put the hex into a Color and try that... edit: just put pink into a Color object, not working either. Commented Sep 7, 2014 at 20:12
  • Also check this out, it has an accepted answer with java code stackoverflow.com/questions/8622104/… Commented Sep 7, 2014 at 20:18

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Cheers, I'll check it out.
@chrana The link is probably useful, but would you be able to explain the information you linked to, or perhaps provide an example using the code? As it is right now, your answer is of questionable usefulness without the link.
I think this will work, just modifying it a little to make it work with my needs.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.