Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to get Color from RGB value in JAVA

  1. Feb 5, 2007 #1
    Is there any way to get color from RGB value?

    for example

    If I give some random RGB value like r=221 g=255 b=123 then how do I get the color associated this RGB value?

    Thanks in advance.
  2. jcsd
  3. Feb 5, 2007 #2


    User Avatar
    Gold Member

  4. Feb 5, 2007 #3


    User Avatar
    Homework Helper

    if you just wanna check what's the color looks like given a set of rgb in decimal, you can quickly check it using simple program like MS Paint.
    Go to custom color and input the rgb values into the appropriate box, and you will see what that color looks like. It is quick too!

    If they are in Hex, convert them into decimal first. most calculators can do that for you.
  5. Feb 5, 2007 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Did you check the constructors for the Color class?
  6. Feb 6, 2007 #5
    This will let you see what various RGB's look like:

  7. Feb 6, 2007 #6
    oh right.. I was looking for the method,
    the Color has a constructor which is
    Color(int r, int g, int b)
    Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).

    another question is how do I control the image transparency?
  8. Feb 14, 2007 #7
    Color Class in Java

    public Color(float r,
    float g,
    float b,
    float a)

    Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

    r - the red component
    g - the green component
    b - the blue component
    a - the alpha component
    Alpha controls image transparency

    -- AI
  9. Mar 4, 2007 #8
    i want to learn from the basics of java script language
    thank you very much if you help me out
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook