Search code examples
javaswingcolorsrgbsrgb

Java Swing JColorChooser Color RGB to sRGB


Is there a way to use the JColorChooser to return a Color that can be converted into their corresponding sRGB float values?

Color backgroundColor = JColorChooser.showDialog(this,"Select a color", default);
float r = backgroundColor.getRed();   //Need these to return float color e.g. 0.9333333f
float g = backgroundColor.getGreen(); 
float b = backgroundColor.getBlue(); 

The default JColorChooser is fine I just need a way to convert the color it returns into 0 to 1 RGB.

I don't understand how to use the API for Color to make this happen. Could someone please provide a example on how to do this? Is it even possible?


Solution

  • Just divide all values by 255 no conversions required