Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

getWriteMetadata

By: a guest on Jun 16th, 2012  |  syntax: Java  |  size: 1.69 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.    private static IIOMetadata getWriteMD(ImageWriter writer, ImageWriteParam param)
  2.         throws IIOInvalidTreeException {               
  3.        
  4.         ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
  5.                 IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, param);
  6.                 if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
  7.                         return null;
  8.                 }
  9.  
  10.         TIFFDirectory dir = TIFFDirectory.createFromMetadata(metadata);
  11.        
  12.         BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
  13.         // getting the tags
  14.         TIFFTag resUnit = base.getTag(BaselineTIFFTagSet.TAG_RESOLUTION_UNIT);
  15.         TIFFTag tagXRes = base.getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION);
  16.         TIFFTag tagYRes = base.getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION);
  17.         TIFFTag photoInterp = base.getTag(BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION);
  18.        
  19.         // (300 x 300 DPI)
  20.         TIFFField fieldXRes = new TIFFField(tagXRes, TIFFTag.TIFF_RATIONAL, 1, new long[][] {{300, 1}});
  21.         TIFFField fieldYRes = new TIFFField(tagYRes, TIFFTag.TIFF_RATIONAL, 1, new long[][] {{300, 1}});
  22.         TIFFField fieldResUnit = new TIFFField(resUnit,BaselineTIFFTagSet.RESOLUTION_UNIT_INCH);
  23.  
  24.         // doesn't work
  25.         dir.removeTIFFField(photoInterp.getNumber());
  26.         TIFFField fieldPhotoInter = new TIFFField(photoInterp, BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_RGB);
  27.  
  28.         // writing to tiffdir
  29.         dir.addTIFFField(fieldXRes);
  30.         dir.addTIFFField(fieldYRes);
  31.         dir.addTIFFField(fieldResUnit);
  32.         dir.addTIFFField(fieldPhotoInter);
  33.  
  34.         return dir.getAsMetadata();
  35.     }
clone this paste RAW Paste Data