简体   繁体   English

使用ColorConverterOp Java将RGB JPEG转换为CMYK JPEG

[英]Convert RGB JPEG to CMYK JPEG using ColorConverterOp Java

I am attempting to convert a jpeg image in rgb to CMYK colorspace. 我正在尝试将rgb中的jpeg图像转换为CMYK颜色空间。 The only problem is my final output is always a black image. 唯一的问题是我的最终输出始终是黑色图像。 But interesting enough the preview application in MAC shows the image correctly. 但是有趣的是,MAC中的预览应用程序可以正确显示图像。 There does not seem to be an example of a successful rgb to cmyk conversion anywhere I've looked so far. 到目前为止,到目前为止,似乎还没有成功将rgb转换为cmyk的示例。 Below is the code i'm using to attempt the conversion. 以下是我尝试进行转换的代码。 This code works fine If i'm performing the conversion to rgb using RGB ICC Profile. 如果我正在使用RGB ICC配置文件执行到rgb的转换,则此代码可以正常工作。 Any guidance is greatly appreciated. 任何指导,不胜感激。

import javax.imageio.ImageIO;

public class TestClass {

  public static void main(String[] args) throws Exception {
    BufferedImage cmykImage = ImageIO.read(new File(
            "CMYK_Sample.jpg"));     
    BufferedImage rgbImage = null;

    ColorSpace cpace = new ICC_ColorSpace(ICC_Profile.getInstance(TestClass.class.getClassLoader().getResourceAsStream("icc/USWebCoatedSWOP.icc")));

    ColorConvertOp op = new ColorConvertOp(cpace, null);       
    rgbImage = op.filter(cmykImage, null);

    ImageIO.write(rgbImage, "JPEG", new File("CMYK_Sample_RGB_OUTPUT2.jpg"));

  }
}

CMYK is for printing. CMYK用于打印。 So, there are few possibilities to show it, except of pdf and postscript files. 因此,除pdf和postscript文件外,几乎没有其他方法可以显示它。 JPEG can show almost only RGB. JPEG几乎只能显示RGB。 So, in your last line ImageIO.write you are trying to read cmyk as RGB. 因此,在最后一行ImageIO.write中,您尝试将cmyk读取为RGB。 Here is the problem. 这是问题所在。

CMYK in JPEG:"Adobe Photoshop and some other prepress-oriented applications will produce four-channel CMYK JPEG files when asked to save a JPEG from CMYK image mode. Hardly anything that's not prepress-savvy will cope with CMYK JPEGs (or any other CMYK format for that matter). When making JPEGs for Web use, be sure to save from RGB or grayscale mode." JPEG中的CMYK:“当系统要求将其从CMYK图像模式保存JPEG时,Adobe Photoshop和其他一些面向印前的应用程序将生成四通道CMYK JPEG文件。几乎所有不具备印前知识的东西都可以处理CMYK JPEG(或任何其他CMYK)格式)。制作用于Web的JPEG时,请确保从RGB或灰度模式保存。” (http://www.faqs.org/faqs/jpeg-faq/part1/) (http://www.faqs.org/faqs/jpeg-faq/part1/)

As for showing CMYK files in java, use java-2d (http://download.oracle.com/javase/1.3/docs/guide/2d/spec/j2d-color.fm2.html) 至于在Java中显示CMYK文件,请使用java-2d(http://download.oracle.com/javase/1.3/docs/guide/2d/spec/j2d-color.fm2.html)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM