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.io.*; 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) { outputSet.removeField(tag); } TiffOutputField imageId = new TiffOutputField(tag, fieldType, tagValue.length(), tagValue.getBytes()); TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory(); exifDirectory.add(imageId); //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) { os.close(); } getInputFile().delete(); temp.renameTo(getInputFile()); }