Package org.apache.sanselan.formats.tiff.write

Examples of org.apache.sanselan.formats.tiff.write.TiffOutputSet


      throws IOException, ImageReadException, ImageWriteException
  {
    OutputStream os = null;
    try
    {
      TiffOutputSet outputSet =  null;

      // note that metadata might be null if no metadata is found.
      IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
      JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
      if (null != jpegMetadata)
      {
        // note that exif might be null if no Exif metadata is found.
        TiffImageMetadata exif = jpegMetadata.getExif();

        if (null != exif)
        {
          // TiffImageMetadata class is immutable (read-only).
          // TiffOutputSet class represents the Exif data to write.
          //
          // Usually, we want to update existing Exif metadata by changing
          // the values of a few fields, or adding a field.
          // In these cases, it is easiest to use getOutputSet() to
          // start with a "copy" of the fields read from the image.
           outputSet = exif.getOutputSet();
        }
      }

      if(null==outputSet)
        outputSet =  new TiffOutputSet();

      {
        // Example of how to remove a single tag/field.
        //
        // Note that this approach is crude: Exif data is organized in
        // directories.  The same tag/field may appear in more than one
        // directory.
        TiffOutputField aperture = outputSet
            .findField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
        if (null != aperture)
        {
          // set contains aperture tag/field.
          outputSet
              .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
        }
      }

      {
        // Example of how to add a field/tag to the output set.
        //
        // Note that you should first remove the field/tag if it already exists
        // in this directory.  See above.
        //
        // Certain fields/tags are expected in certain Exif directories;
        // Others can occur in more than one directory (and often have a different
        // meaning in different directories).
        //
        // TagInfo constants often contain a description of what directories
        // are associated with a given tag.
        //
        // see org.apache.sanselan.formats.tiff.constants.AllTagConstants
        //
        TiffOutputField aperture = TiffOutputField.create(
            TiffConstants.EXIF_TAG_APERTURE_VALUE,
            outputSet.byteOrder, new Double(0.3));
        TiffOutputDirectory exifDirectory = outputSet
            .getOrCreateExifDirectory();
        exifDirectory.add(aperture);
      }

      {
        // Example of how to add/update GPS info to output set.

        // New York City
        double longitude = -74.0; // 74 degrees W (in Degrees East)
        double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees North)

        outputSet.setGPSInDegrees(longitude, latitude);
      }

      //      printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);

      os = new FileOutputStream(dst);
View Full Code Here


        IImageMetadata metaData = Sanselan.getMetadata(f);
        JpegImageMetadata jMetaData = (JpegImageMetadata) metaData;
        assert (jMetaData != null);
        TiffImageMetadata exif = jMetaData.getExif();
        TiffOutputSet outputSet = exif.getOutputSet();
        TiffOutputField field = outputSet.findField(TiffConstants.EXIF_TAG_PROCESSING_SOFTWARE);
        if (null != field) {
      outputSet.removeField(TiffConstants.EXIF_TAG_PROCESSING_SOFTWARE);
      String fieldString = "Edited by DeExifier. andreas.reichart@gmail.com";
      TiffOutputField newField = new TiffOutputField(ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE,
        TiffFieldTypeConstants.FIELD_TYPE_ASCII, fieldString.length(), fieldString.getBytes());
      TiffOutputDirectory outDirectory = outputSet.getOrCreateExifDirectory();
      outDirectory.add(newField);
        }

        eRewriter.updateExifMetadataLossless(imageByte, bOutputStream, outputSet);

    }

    // if (removeExif & removeIptc) {
    // TODO: removeExif & removeIptc
    // }

    // OK, works: recompressed image is already empty.
    if (!removeExif && !removeIptc) {

        IImageMetadata metadata = Sanselan.getMetadata(f);
        JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
        if (jpegMetadata != null) {
      TiffImageMetadata exif = jpegMetadata.getExif();
      if (exif != null) {
          TiffOutputSet outputSet = exif.getOutputSet();
          TiffOutputSet emptySet = new TiffOutputSet();
          new ExifRewriter().removeExifMetadata(imageByte, bOutputStream);
      }
        }
    }
      }
View Full Code Here

TOP

Related Classes of org.apache.sanselan.formats.tiff.write.TiffOutputSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.