commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Arnold <>
Subject [Sanselan] Writing Metadata to existing TIFF
Date Fri, 10 Jun 2011 19:59:26 GMT
First off, I first [incorrectly] posted this to dev, instead of user. So, my

I'm attempting to use the Sanselan library to add metadata to a TIFF file,
however, I don't know how to accomplish this. I've successfully accomplished
this with a Jpeg, but I don't know what changes need to be done to co-opt
this code for TIFFs. I'll be seperating out the primary sections of code to
a common function, but I've simplified the Jpeg code for posting here. So,
any thoughts on how to accomplish doing the same with a TIFF?

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

import org.apache.sanselan.*;
import org.apache.sanselan.common.*;
import org.apache.sanselan.formats.tiff.TiffImageMetadata;
import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossless;
import org.apache.sanselan.formats.tiff.write.TiffOutputDirectory;
import org.apache.sanselan.formats.tiff.write.TiffOutputField;
import org.apache.sanselan.formats.tiff.write.TiffOutputSet;

public void DoSomething(String tagName, String tagValue){

  File inputFile = getInputFile();

  IImageMetadata data = null;

  OutputStream os = null;

  data = Sanselan.getMetadata(inputFile);

  TiffOutputSet outputSet = null;

  outputSet = getExif(data);

  TiffOutputField imageHistoryPre = outputSet.findField(tag);

  if (imageHistoryPre != null) {



  TiffOutputField imageId = new TiffOutputField(tag, fieldType,
tagValue.length(), tagValue.getBytes());

  TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();


//everything after this is where I get confused.

  File temp;

  temp = File.createTempFile("FileTaggingProcessingFile", null);

  os = new FileOutputStream(temp);

  os = new BufferedOutputStream(os);

  if (data instanceof JpegImageMetadata) {

   new ExifRewriter().updateExifMetadataLossless(inputFile, os, outputSet);


  if (os != null) {






  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message