Results 1 to 13 of 13
  1. #1
    zit1343 is offline Member
    Join Date
    Jan 2011
    Posts
    17
    Rep Power
    0

    Default RGB to Color Name

    hey
    I m trying to learn how to java & android app devp at the same time
    I am trying to convert rgb numbers to color name like black blue orange or whtever the rgb generate
    I just want to know how to do RGB to color name
    thanx

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Maybe look at the static final variables in Color?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ra4king View Post
    Maybe look at the static final variables in Color?
    Yep, set up a Map<Color, String> and fill them with those name, value pairs but reversed:

    Java Code:
    Map<Color, String> map= new HashMap<Color, String>() {{
       add(Color.BLUE, "blue");
       add(Color.RED, "red");
       ...
    }};
    Of course you can add other value pairs as well.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    @JosAH
    Would you want to do Map<String, Color> so you can get the value (Color) specified by the key (String)?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ra4king View Post
    @JosAH
    Would you want to do Map<String, Color> so you can get the value (Color) specified by the key (String)?
    Nope, the OP wants to supply a colour value RGB and find the name of the colour.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Oh I was thinking of this more like shortcut names. "setColor(map.get("mySpecialColor"));"

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ra4king View Post
    Oh I was thinking of this more like shortcut names. "setColor(map.get("mySpecialColor"));"
    Sure, that can have its use as well, but the little obedient puppy that I am, I just answered the OPs question.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Good puppy :) *pat on the head* Don't listen to this grumpy old dog :p

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ra4king View Post
    Good puppy :) *pat on the head* Don't listen to this grumpy old dog :p
    Arf! Arf! <pees on shoes/>

    kind regards,

    Jos (<-- fine young christian law obedient citizen)
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Now you've ruined my shoes :mad:

    Well, Happy Easter anyways!

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ra4king View Post
    Now you've ruined my shoes :mad:

    Well, Happy Easter anyways!
    Same to you (the weather is great overhere for a change).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. if (...) ... won't set color
    By livingdog in forum New To Java
    Replies: 6
    Last Post: 04-11-2010, 03:59 PM
  2. RGB from Color Name
    By winklerd in forum Advanced Java
    Replies: 5
    Last Post: 03-26-2010, 05:16 PM
  3. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 04:27 AM
  4. Color gradient
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 08:50 PM
  5. A bit of color!
    By tim in forum Java 2D
    Replies: 8
    Last Post: 02-11-2008, 11:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •