Uncompress a TIFF file without going through BufferedImage

Posted by Gert on Stack Overflow See other posts from Stack Overflow or by Gert
Published on 2012-06-01T09:39:20Z Indexed on 2012/06/01 10:41 UTC
Read the original article Hit count: 323

Filed under:
|
|
|

I am receiving large size CCITT Group 4 compressed TIFF files that need to be written elsewhere as uncompressed TIFF files. I am using the jai_imageio TIFF reader and writer to do that and it works well as long as the product _width * height_ of the image fits in an integer.

Here is the code I am using: TIFFImageReaderSpi readerSpi= new TIFFImageReaderSpi(); ImageReader imageReader = readerSpi.createReaderInstance(); byte[] data = blobManager.getObjectForIdAndVersion(id, version); ImageInputStream imageInputStream = ImageIO.createImageInputStream(data); imageReader.setInput(imageInputStream);

TIFFImageWriterSpi writerSpi = new TIFFImageWriterSpi();
ImageWriter imageWriter = writerSpi.createWriterInstance();
ImageWriteParam imageWriteParam = imageWriter.getDefaultWriteParam();
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);
//bufferFile is created in the constructor
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(bufferFile);
imageWriter.setOutput(imageOutputStream);

//Now read the bitmap
BufferedImage bufferedImage = imageReader.read(0);
IIOImage iIOImage = new IIOImage(bufferedImage, null, null);
//and write it
imageWriter.write(null, iIOImage, imageWriteParam);

Unfortunately, the files that I receive are often very large and the BufferedImage cannot be created. I have been trying to find a way to stream from the ImageReader directly to the ImageWriter but I cannot find out how to do that. Anybody with a suggestion?

© Stack Overflow or respective owner

Related posts about java

Related posts about tiff