javagraphicsrgbcmyk

Draw CMYK Color from RGB


Hello. I have a screen like above. By using the sliders, I get red, green, blue. Also, I calculate cyan, magenta, yellow and from red, green, blue for CMYK. My question is that is there any way to show CMYK colour in java like light purple in the picture.

private void stateChanged() {
      red= sliderRed.getValue();
      green= sliderGreen.getValue();
      blue= sliderBlue.getValue();
      txt_background.setBackground(new Color(red, green, blue));
}

Solution

  • It looks to me like the java color class, has a constructor for making a color object in cmyk

    https://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#Color(java.awt.color.ColorSpace,%20float[],%20float)

    and

    https://docs.oracle.com/javase/7/docs/api/java/awt/color/ColorSpace.html

    So you would end up with something like

    Color cmykColorValue = new Color(TYPE_CMYK, [cValue, mValue, yValue, kValue], alpha)

    Where alpha is form 0 to 1, and cValue, mValue, yValue, kValue are the corresponding cmyk values.

    That should make a new CMYK color object that can be used anywhere a color object can be used.