• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get color name

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I'm trying to get a color name to do some checking?
Suppose when the color instantiation is



The output i'm getting is :


I want to have the color name like red, blue, green etc..
How it can be done?
Regards.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out http://www.exampledepot.com/egs/java.awt/color_Str2Clr.html
This will only work for predefined color fields in the java.awt.Color class.
If you want custom colors like say "Mountbatten Pink" you will have to define your own mappings.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not every R/G/B combination has a name, and in any case it's very likely that not everyone agrees on which name should go with which R/G/B triplet.

As far as java.aw.Color is concerned, a few names are defined in its source code.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Not every R/G/B combination has a name,


Right. There are over 16 million colors available with the RGB model. For pure grey alone there are 256 - 2 = 254 colors! (X,X,X with X between 1 and 254 inclusive; 0 is black and 255 is white) Would you like to name all these colors?

Now between X,X,Y and X,X,Y+1 there is hardly any difference, so perhaps you can do some grouping, but that still leaves thousands of color groups to name.
reply
    Bookmark Topic Watch Topic
  • New Topic