Java 9 TIFF Image I/O plugins

In earlier version of Java, Image I/O Framework javax.imageio provides a standard way to plug-in image codecs for some formats such as PNG and JPEG. But TIFF is still missing from this set. It was packaged in before. Java 9 TIFF Image I/O plugins has a new package called javax.imageio.plugins.tiff which is renamed from

In this article, we’re gonna take a look at that package and test a simple example.

I. javax.imageio.plugins.tiff

The package contains some classes that support the built-in TIFF reader and writer plug-ins. It includes:
– Some classes representing common additional tags and the set of tags found in baseline TIFF specification, Exif IFD, TIFF-F (RFC 2036) file, GeoTIFF IFD.
TIFFImageReadParam: an extension of ImageReadParam which can specify which metadata tags are allowed to be read and set some destination properties.

For more details, please visit:
javax.imageio.plugins.tiff – Package Summary
TIFF Metadata Format Specification and Usage Notes.

II. Example

In the example, we will read an input stream of TIFF image, set its metadata tags and destination offset. Then we write data after processing to another TIFF image as result.

This is source code:

package com.javasampleapproach.tiffimageio;

import java.awt.Point;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;

import javax.imageio.plugins.tiff.*;

public class MainApp {

	public static void main(String[] args) throws IOException {

		InputStream stream = new URL(

		ImageReader tiffReader = ImageIO.getImageReadersByFormatName("tiff").next();

		ImageInputStream input = ImageIO.createImageInputStream(stream);


		TIFFImageReadParam mTIFFImageReadParam = new TIFFImageReadParam();

		System.out.println("--- TIFFImageReadParam - default TagSets ---");

		// mTIFFImageReadParam.removeAllowedTagSet(ExifParentTIFFTagSet.getInstance());
		// mTIFFImageReadParam.removeAllowedTagSet(GeoTIFFTagSet.getInstance());
		System.out.println("--- TIFFImageReadParam - after removing 2 TagSets ---");

		mTIFFImageReadParam.setDestinationOffset(new Point(20, 20));

		// Read primary image and IFD.
		BufferedImage image =, mTIFFImageReadParam);

		System.out.println("--- TIFFImage after retrieving---");
		System.out.println("- Height: " + image.getHeight());
		System.out.println("- Width: " + image.getWidth());
		IIOMetadata metaData = tiffReader.getImageMetadata(0);
		System.out.println("NativeMetadataFormatName: " + metaData.getNativeMetadataFormatName());

		// write Image
		File newTIFFimage = new File("newTiffImage.tiff");
		ImageIO.write(image, "TIFF", newTIFFimage);


The input TIFF image with the size[240,240] will be read by ImageReader.
By default, TIFFImageReadParam adds 4 TagSets: BaselineTIFFTagSet, FaxTIFFTagSet, ExifParentTIFFTagSet, GeoTIFFTagSet in its constructor method. We remove 2 TagSets, then set offset in the destination image by [20,20]. So the image after using read() method will be shifted and increase its height and width by 20 pixels.

The image below shows details inside ImageReader tiffReader variable:

Run the code, console window shows:

--- TIFFImageReadParam - default TagSets ---
--- TIFFImageReadParam - after removing 2 TagSets ---
--- TIFFImage after retrieving---
BufferedImage@2f490758: type = 0 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1dd92fe2 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 260 height = 260 #numDataElements 3 dataOff[0] = 0
- Height: 260
- Width: 260
NativeMetadataFormatName: javax_imageio_tiff_image_1.0

And this is the exported TIFF image:
newTiffImage.tiff - click to download

By grokonez | March 30, 2017.

Last updated on April 28, 2021.

Related Posts

Got Something To Say:

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