jai-imageio / jai-imageio-core

JAI ImageIO Core (without javax.media.jai dependencies)
Other
234 stars 88 forks source link

Tiff compression does not seem to work #28

Closed jnankin closed 8 years ago

jnankin commented 8 years ago

Here is some code using the JAI (1.3.1) Github release:

TIFFImageReader imageReader = getTiffImageReader();
imageReader.setInput(is);

TIFFImageWriter imageWriter = getTiffImageWriter();
ImageOutputStream ios = ImageIO.createImageOutputStream(new File(outputFilename));

imageWriter.setOutput(ios);

TIFFImageWriteParam writeParam =  (TIFFImageWriteParam)imageWriter.getDefaultWriteParam();
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("CCITT T.6");
imageWriter.prepareWriteSequence(null);

int pageNumbers = imageReader.getNumImages(true);

for (int i = 0; i < pageNumbers; i++){
    BufferedImage currentPage = imageReader.read(i);
    IIOImage iiom = new IIOImage(currentPage, null, null);
    imageWriter.writeToSequence(iiom, writeParam);
}

imageWriter.endWriteSequence();
imageWriter.dispose();
ios.flush();
ios.close();

When I run an input file through here that is roughly 55kb, it bloats it to 3.7mb. The file size does not change if I remove writeParam from imageWriter.writeToSequence.

Why is the file not lower under compression?

jnankin commented 8 years ago

I was writing over an existing file which was generating a corrupt file.

songshiliang07 commented 5 years ago

Here is some code using the JAI (1.3.1) Github release:

TIFFImageReader imageReader = getTiffImageReader();
imageReader.setInput(is);

TIFFImageWriter imageWriter = getTiffImageWriter();
ImageOutputStream ios = ImageIO.createImageOutputStream(new File(outputFilename));

imageWriter.setOutput(ios);

TIFFImageWriteParam writeParam =  (TIFFImageWriteParam)imageWriter.getDefaultWriteParam();
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("CCITT T.6");
imageWriter.prepareWriteSequence(null);

int pageNumbers = imageReader.getNumImages(true);

for (int i = 0; i < pageNumbers; i++){
    BufferedImage currentPage = imageReader.read(i);
    IIOImage iiom = new IIOImage(currentPage, null, null);
    imageWriter.writeToSequence(iiom, writeParam);
}

imageWriter.endWriteSequence();
imageWriter.dispose();
ios.flush();
ios.close();

When I run an input file through here that is roughly 55kb, it bloats it to 3.7mb. The file size does not change if I remove writeParam from imageWriter.writeToSequence.

Why is the file not lower under compression?

Does this resolved?