how can I convert an RGB image to CMYK and vice versa in Java?

前端 未结 4 1902
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 01:03

our web app let users download dynamically generated images in different formats (bmp, png and jpeg). Some of our users download the images for printing, thus we would like

4条回答
  •  悲哀的现实
    2020-12-21 02:06

    Suggest using fromRGB() - see http://download.oracle.com/javase/1.4.2/docs/api/java/awt/color/ColorSpace.html

    Sample code:

    java.awt.color.ColorSpace
    
    ColorSpace cmyk = new ColorSpace(ColorSpace.TYPE_CMYK, 4);
    float[] values = cmyk.fromRGB(rgbFloatArray);
    

    public abstract float[] fromRGB(float[] rgbvalue)

    Transforms a color value assumed to be in the default CS_sRGB color space into this ColorSpace.

    This method transforms color values using algorithms designed to produce the best perceptual match between input and output colors. In order to do colorimetric conversion of color values, you should use the toCIEXYZ method of the CS_sRGB color space to first convert from the input color space to the CS_CIEXYZ color space, and then use the fromCIEXYZ method of this color space to convert from CS_CIEXYZ to the output color space. See toCIEXYZ and fromCIEXYZ for further information.

提交回复
热议问题