How to Write to a TIFF File with Oracle JDK

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

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;

public final class TiffSample {

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

    if (it.hasNext()) {
      final ImageWriter writer = it.next();

      final DataOutput out = new FileImageOutputStream(new File("sample.tif"));

      writer.setOutput(out);

      final IIOImage image = ...

      writer.writeInsert(0, image, 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