Skip to main content

TIFF compression

2 replies [Last post]
spgmx
Offline
Joined: 2009-05-10

Hi,

I'm reading an image via ImageIO.read into a BufferendImage and write it out with TIFF G4 (CCITT T.6). But the resulting file is really big. So I tried a TIFF G4 as source and it became 3 times bigger (33 KB -> 100 KB). What is the problem in my code?

private ImageOutputStream ios;
private ImageWriter writer;
private TIFFImageWriteParam writeParam;

Iterator it = ImageIO.getImageWritersByFormatName("TIF");
writer = (ImageWriter) it.next();
ios = ImageIO.createImageOutputStream(destFile);
writer.setOutput(ios);
writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("CCITT T.6");
IIOImage img = new IIOImage(ImageIo.read(srcFile), null, null);
writer.write(null, img, writeParam);
ios.close();
writer.dispose();

Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcojacob
Offline
Joined: 2006-07-10

There are several parameters reading and writing TIFF. You write Fax G4
(BaselineTIFFTagSet.COMPRESSION_CCITT_T_6) with default parameters
only setting Locale and compression type.

You could get the image reader like you did for the writer, use reader.readall to
get an IIOImage that includes the original metadata and then write a
new image with this metadata. Furthermore you can find out, which
Fax G4 parameters are set different.

spgmx
Offline
Joined: 2009-05-10

Hi,

the CompressionNode of the original TIFF has only default settings.
And I have no idea why the compression ratio is that bad... :(

Shouldn't TIFF G4 always be the same?

Any idea?