Java将CMYK图像保存到文件

我正在尝试在CMYK Colorspace中创建图像,并在使用它之后,例如绘画线等,将其保存到文件中。不幸的是,互联网上没有关于java中CMYK的大量信息。我发现只有一篇文章http://carback.us/rick/blog/?p=58。但是使用iText库将图像保存到Pdf。但我需要它保存到png或jpeg文件。这是代码:
public BufferedImage createCMYKBufferedImage(double l_width, double l_height) {
    ColorSpace colorSpace = SimpleCMYKColorSpace.getInstance();
    ComponentColorModel l_ccm = new ComponentColorModel(colorSpace, false, false,
                            1, DataBuffer.TYPE_FLOAT);
    int[] l_bandoff = {0, 1, 2, 3}; //Index for each color (C, is index 0, etc)
    PixelInterleavedSampleModel l_sm = new PixelInterleavedSampleModel(
                               DataBuffer.TYPE_FLOAT,
                               (int)l_width, (int)l_height,
                                   4,(int)l_width*4, l_bandoff);
    WritableRaster l_raster = WritableRaster.createWritableRaster(l_sm,
            new Point(0, 0));
    return new BufferedImage(l_ccm, l_raster, false, null);
}
当我试图保存图像时,我只是在打电话   ImageIO.write(图片,格式,文件); 有谁能够帮我?     
已邀请:
将BufferedImage写为Jpeg: 首先,将BufferedImage转换为Jpeg字节数组。
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public static byte[] jpegToBytes(BufferedImage image) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
    JPEGEncodeParam jparm = encoder.getDefaultJPEGEncodeParam(image);
    jparm.setQuality(1F, false);

    try {
        encoder.encode(image, jparm);
        os.close();
    } catch (IOException e) {
        EclipseLogging.logError(RabidPhotoPlugin.getDefault(),
                RabidPhotoPlugin.PLUGIN_ID, e);
        return new byte[0];
    }
    return os.toByteArray();
}
接下来,将字节数组写入文件。
public static void writePhoto(byte[] photo) {
    try {
        OutputStream os = new FileOutputStream('file name');
        os.write(photo);
        os.flush();
        os.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
    
看来,你在这个问题上有争议。 Jpeg和PNG具有RGB图像格式。例如,看 http://forums.adobe.com/message/2704225。 因此,您必须将源图片直接放入png / jpeg或将CMYK打印到pdf。 CMYK是一种打印格式,而不是屏幕格式。     

要回复问题请先登录注册