I am looking for a way to input a 6-digit RGB-hex number and then be able to click on a button that will display the corresponding color name. Unfortunately, I have not been able to find a color library in Java that can provide me with the names of arbitrary colors.
My approach: I came across a JavaScript library called "ntc js lib" which assigns names to colors based on their hex values. I tried to replicate this functionality in Java by creating a hash map where each key-value pair represents a hex color value and its corresponding name, like so:
sColorNameMap.put("B43332", "Well Read");
The code works fine if I input a key that matches one of the values stored in the hash map. For example, when I enter the value B43332, it correctly returns the name "Well Read".
My issue: However, I am facing difficulties when entering a value that does not exactly match any of the keys in the hash map. In such cases, I am unable to retrieve the color name.
What I require: I am in need of a function that can return the name of the closest matching color. I have attempted to understand how the ntc library achieves this but have been unsuccessful in doing so.
For instance, the value B23634
is not predefined in the ntc js lib, yet it resolves to the name "Well Read," as depicted in this image:
https://i.sstatic.net/1SB6S.png
Any guidance or assistance in implementing a function that can determine the closest matching color based on a given 6-digit hex value would be greatly appreciated.