suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How to read TIFF images in Java

1 min read

In this article, I will explain how to read Tiff files in Java.

ImageIO does not read TIFF file types by default so you will need to use an ImageIO plugin or an external library. I will demonstrate using an Open source ImageIO plugin called TwelveMonkeys (which extends ImageIO to provide TIFF reading support), and using the JDeli Image Library.

What is TIFF?

TIFFTIFF stands for “Tag Image File Format”. It is a complex file format for storing one or more bitmapped images in multiple colourspaces using several different forms of compression.

The file name extension for TIFF files is: .tif, .tiff

How to read a TIFF image in Java with ImageIO

Step 1 Download TwelveMonkeys plugin and add to your class path.
Step 2 Create a File handle, InputStream, or URL pointing to the raw TIFF image.
Step 3 ImageIO will now be able to read a TIFF file into a BufferedImage.

BufferedImage image = ImageIO.read(tiffFileOrInputStreamOrURL)

How to read a TIFF image in Java with JDeli

Step 1 Add JDeli to your class or module path. (download the trial jar).
Step 2 Create a File handle, InputStream pointing to the raw TIFF image. You can also use a byte[] containing the image data.
Step 3 Read the TIFF image into a BufferedImage

BufferedImage image = JDeli.read(tiffFile);

How to read a multi-file TIFF image in Java with JDeli

Step 1 Add JDeli to your class or module path. (download the trial jar).
Step 2 Create a File handle, InputStream pointing to the raw TIFF image. You can also use a byte[] containing the image data.
Step 3 Read the TIFF file into a TiffDecoder instance

RandomAccessFile raf = new RandomAccessFile("yourTiffFileLocation", "r");
TiffDecoder decoder = new TiffDecoder(raf);

Step 4 Loop through the separate images in the TIFF file

for (int i = 1; i <= decoder.getPageCount(); i++) {
BufferedImage decodedImage = decoder.read(i);
  // Insert BufferedImage handling code here
}
raf.close();

Why use JDeli to read TIFF?

JDeli offers a range of advantages over ImageIO and alternatives, including:

  • prevents heap related JVM crashes
  • reads 1-32 bit bilevel, grayscale, rgb, argb, cmyk, acmyk, ycbcr Colorspaces, and converts to sRGB BufferedImage
  • implements both Little and Big Endian Byte Ordering
  • decompresses uncompressed, CCITT group 3 and 4, Deflate/Adobe Deflate, LZW, Packbits
  • support for Single, Multi-file, Tiling, Planar (Chunky, Separated), Predictor, 16,32 bit floating samples
  • improve read performance
  • supports threading
  • superior image scaling algorithms

Learn more about JDeli, or download it to try it yourself.

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How to read HEIC image files in Java with…

In this article, I will explain how to read HEIC files into Java as a BufferedImage. ImageIO does not read HEIC file types so...
Mark Stephens
1 min read

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

2 Replies to “How to read TIFF images in Java”

  1. Hi

    I want to get the bit depth of tiff file. i tried through Apache TIKA but able to get only the mime type.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2020. All rights reserved.