• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get color name

 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11069
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic