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 (Tutorial)

1 min read

TIFF icon

TIFF

Why do TIFF Images cause issues for Java Developers?

ImageIO does support TIFF file types by default but it is not a complete implementation. It also changed in the move from Java 8 to Java 11, meaning a lot less TIFF files now work with it. If you have an existing Java Application using ImageIO you will find it cannot process all TIFF images.

In this post, I will cover how to upgrade ImageIO to support TIFF files so existing Java Applications which use ImageIO will work with more TIFF files (often without having to make any code changes) and how to read TIFF files in JDeli directly.

What options are there for reading TIFF files in Java?

Java does read some TIFF images by default but you will need to use an external library or plugin for ImageIO if you want to handle more of them. JDeli gives you full support for TIFF in pure Java and can also be used as an ImageIO plugin.

If you are looking for a free solution, the Download TwelveMonkeys plugin offers TIFF support. In this article we will be using our JDeli pure Java library which can read, write and convert TIFF files.

How to upgrade ImageIO to read TIFF files

It’s actually very simple and can be done without rewriting your existing code!

For example, the code below does not work with ImageIO for all TIFF images


Steps to fix with JDeli:

How to read a TIFF image in Java with JDeli

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

and the Java code to read a TIFF with JDeli…

Try print the result: if it works, it will print the image information

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

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

and the Java code to read a multi-TIFF with JDeli…

Other useful TIFF links



Are you a Java Developer working with Image files?

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

2 Replies to “How to read TIFF images in Java (Tutorial)”

  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.

Comments are closed.