How to Read an Image from a TIFF File with Oracle JDK

import java.io.File;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;

public final class TiffSample {

  public static void main(final String[] args) throws Exception {
    final Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName("tiff");

    if (it.hasNext()) {
      final ImageReader reader = it.next();

      final ImageInputStream input = new FileImageInputStream(new File("image.tiff"));

      reader.setInput(input);

      reader.readAll(0, null); // for the first image
    }

  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s