Java’s ImageIO package (built in) does not support Tiff file decoding. So either you need JAI plugin or other third party libraries to convert these files into buffered images. Support for Tiff images in both is not complete.
The third party Java libraries support only a subset of the Tiff files. (example tiling, separated planar, jpeg compression, multi page). So we decided to provide Tiff encoding and decoding support in JDeli. This is a complete ImageIO replacement.
Here is a simple example of how you can use the library to decode raw tiff bytes:
TiffDecoder decoder = new TiffDecoder(rawTiffData); BufferedImage decodedImage = decoder.read(); |
or using RandomAccessFile:
RandomAccessFile raf = new RandomAccessFile("yourFileLocation","r"); TiffDecoder decoder = new TiffDecoder(raf); BufferedImage decodedImage = decoder.read(); //insert your buffered image handling code here; raf.close(); |
The code below exemplifies how to decode multi page tiff files:
RandomAccessFile raf = new RandomAccessFile("yourFileLocation", "r"); TiffDecoder decoder = new TiffDecoder(raf); for (int i = 1; i <= decoder.getPageCount(); i++) { BufferedImage decodedImage = decoder.read(i); // Insert BufferedImage handling code here } raf.close(); |
Technical features
The Tiff file format is actually a whole collection of possible settings. Here is the full list which JDeli supports.
Available decompression techniques:
- uncompressed
- CCITT group 3 and 4
- Deflate/Adobe Deflate
- LZW
- Packbits
- Jpeg Technote 2 ( please note: old-style jpeg compression support is not added the reason can be found here).
Tiff Decoder also supports:
- Colorspace: bilevel, grayscale, rgb, argb, cmyk, acmyk, ycbcr
- Bits Per Sample : 1 to 32
- Byte Ordering : Little and Big Endian
- Other : Single, Multi file, Tiling, Planar (Chunky, Separated), Predictor, 16,32 bit floating samples
I hope you may find it useful and make use of the features in the JDeli Image Library.
We have also created a useful how to series on how to read and write various Image formats.
IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.
Hi
I want to get the bit depth of tiff file. i tried through Apache TIKA but able to get only the mime type.
Hi Vikash,
Getting the bit depth is something that we could add to our image library, JDeli. If you are interested in purchasing JDeli you can find out more here.