File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get color name

 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • 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: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • 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
Pie
Posts: 42966
73
  • 0
  • 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: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic