aspose file tools*
The moose likes Java in General and the fly likes How to get color name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get color name" Watch "How to get color name" New topic
Author

How to get color name

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42918
    
  68
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

Joined: Oct 27, 2005
Posts: 19783
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get color name