Color c = new Color(255, 125, 0); float [] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); System.out.println("Hue: "+hsb[0]); // Hue: 0.08333333 System.out.println("Saturation: "+hsb[1]); // Saturation: 1.0 System.out.println("Brightness: "+hsb[2]); // Brightness: 1.0
Color [] colors = new Color[3]; colors[0] = new Color(255, 0, 0); // Red colors[1] = new Color(0, 255, 0); // Green colors[2] = new Color(0, 0, 255); // Blue for(Color c : colors) { float [] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); System.out.println(c.toString()+" Hue: "+hsb[0]+" Saturation: "+hsb[1]+" Brightness: "+hsb[2]); }In this example, we create an array of three Color objects (Red, Green, and Blue). We then loop through each Color and use the RGBtoHSB method to convert the RGB values into HSB values. We print out the Hue, Saturation, and Brightness values for each Color. Package library: java.awt