Does someone know how to set up the COMPRESSION_CCITT_T_4 when writting a TIFF file please?
You can give a TIFFImageWriteParam for writing with ImageIO and set the compression
to COMPRESSION_CCITT_T_4. Be aware that TIFF support is in the separate lib
Thank your for your answer.
Here is the code I use :
// paramÃ©trage du Tiff Writer
ios = ImageIO.createImageOutputStream(tiffFile);
TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
I tested it on 1 document scanned with my applet and I have 2 problems on the returned TIFF:
- I have the scanned document, but like if I had apply an invert (inversion?) filter (please excuse my English I'm French!)
- The file size seems to big : 171ko
Then, I opened the returned TIFF in Gimp and saved it in TIF choosing CCITT Group 4 and the new file has no inversion effect and its size is 52ko.
Can someone help me correct these problems please?
I guess you need to convert the ColorSpace of the image to bilevel with JAI.
It depends on the kind of file you get. I don't know the best solution to
convert grayscale or color images to bilevel. You may ask at JAI forum.
----- copy from TIFFImageWriteParam javadoc -----
"The CCITT compression types are applicable to bilevel (1-bit) images only"
----- end copy from TIFFImageWriteParam javadoc -----
I thing my image is already in bilevel ; if it was not may be I would get an error telling me it can not be compressed as the image is not bilevel?
This is my code to convert the image I get from the scanner to a PlanarImage
protected PlanarImage MorenaImageToPlanarImage(MorenaImage morenaImage)
Image image = Toolkit.getDefaultToolkit().createImage(morenaImage);
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);
bufferedImage.createGraphics().drawImage(image, 0, 0, null);
PlanarImage planarImage = PlanarImage.wrapRenderedImage(bufferedImage);
Does this line set up the image to bilevel? BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);
I opened my TIFF in a real Tiff viewer called XnView and in fact the TIFF I get has no invert effect.
When I displayed the parameter of the TIFF I saw : Photometric Interpretation: Black=0
So I solved the problem of invert effect by setting up the TAG_PHOTOMETRIC_INTERPRETATION with the BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO constant.
But I am still having the file length to big (about 156ko). I expect to have a file about 50 ko. Any idea please?
Message was edited by: jack987
There are several factors that can impact on the size.
Maybe the conversion to bilevel has a different result.
Maybe the other software does some more work to the image to improve the quality
without mention it.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.