[OpenJDK 2D-Dev] Writing a CMYK file

Adam Augusta roxton at gmail.com
Tue Jun 17 16:27:19 UTC 2008


I just wanted to share my prototyped solution to this.  The answer was
staring me in the face, but it may prove useful to someone else.

final DataBufferByte buffer = new DataBufferByte(myCmykByteArray,
myCmykByteArray.length);
final WritableRaster raster = Raster.createInterleavedRaster(buffer,
imageWidth, imageHeight, imageWidth*4, 4, new int[] {0, 1, 2, 3}, new
Point(0,0));


final ICC_Profile profileCmyk;
try {
    profileCmyk = ICC_Profile.getInstance("c:\\myprofile.icc");
} catch (IOException e) {
...
}

final ICC_ColorSpace colorSpaceCmyk = new ICC_ColorSpace(profileCmyk);
final ColorModel model = new ComponentColorModel(colorSpaceCmyk, new
int[] {8,8,8,8}, false, false, ColorModel.OPAQUE,
DataBuffer.TYPE_BYTE);

BufferedImage bufferedImage = new BufferedImage(model, raster, false, null);
final File output = new File("c:\\fileoutput.tif");
final FileImageOutputStream outputStream;
try {
    outputStream = new FileImageOutputStream(output);
} catch (IOException e) {
...
}

final ImageWriter writer =
ImageIO.getImageWritersByMIMEType("image/tiff").next();

writer.setOutput(outputStream);

try {
    writer.write(bufferedImage);
} catch (IOException e) {
    throw new RuntimeException("Oh noes", e);
}

-Adam



More information about the 2d-dev mailing list