Examples of TiffOutputSet


Examples of org.apache.commons.imaging.formats.tiff.write.TiffOutputSet

    }

    public TiffOutputSet getOutputSet() throws ImageWriteException {
        final ByteOrder byteOrder = contents.header.byteOrder;
        final TiffOutputSet result = new TiffOutputSet(byteOrder);

        final List<? extends IImageMetadataItem> srcDirs = getDirectories();
        for (IImageMetadataItem srcDir1 : srcDirs) {
            final Directory srcDir = (Directory) srcDir1;

            if (null != result.findDirectory(srcDir.type)) {
                // Certain cameras right directories more than once.
                // This is a bug.
                // Ignore second directory of a given type.
                continue;
            }

            final TiffOutputDirectory outputDirectory = srcDir
                    .getOutputDirectory(byteOrder);
            result.addDirectory(outputDirectory);
        }

        return result;
    }
View Full Code Here

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 file does not contain any exif metadata, we create an empty
            // set of exif metadata. Otherwise, we keep all of the other
            // existing tags.
            if (null == outputSet)
                outputSet = new TiffOutputSet();

            {
                // 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, or you may end up with duplicate
                // tags. 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();
                // make sure to remove old value if present (this method will
                // not fail if the tag does not exist).
                exifDirectory
                        .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
                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

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

            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)
            {
                // file does not contain any exif metadata. We don't need to
                // update the file; just copy it.
                IOUtils.copyFileNio(jpegImageFile, dst);
                return;
            }

            {
                // Example of how to remove a single tag/field.
                // There are two ways to do this.

                // Option 1: brute force
                // Note that this approach is crude: Exif data is organized in
                // directories. The same tag/field may appear in more than one
                // directory, and have different meanings in each.
                outputSet.removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);

                // Option 2: precision
                // We know the exact directory the tag should appear in, in this
                // case the "exif" directory.
                // One complicating factor is that in some cases, manufacturers
                // will place the same tag in different directories.
                // To learn which directory a tag appears in, either refer to
                // the constants in ExifTagConstants.java or go to Phil Harvey's
                // EXIF website.
                TiffOutputDirectory exifDirectory = outputSet
                        .getExifDirectory();
                if (null != exifDirectory)
                    exifDirectory
                            .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
            }
View Full Code Here

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

            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 file does not contain any exif metadata, we create an empty
            // set of exif metadata. Otherwise, we keep all of the other
            // existing tags.
            if (null == outputSet)
                outputSet = new TiffOutputSet();

            {
                // 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);
            }

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

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

                assertTrue(!hasExifData(tempFile));
            }

            {
                TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
                //            outputSet.dump();

                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                new ExifRewriter().updateExifMetadataLossy(stripped, baos,
View Full Code Here

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

                oldMetadata.dump();

                //            TiffImageMetadata tiffImageMetadata = metadata.getExif();
                //            Photoshop photoshop = metadata.getPhotoshop();

                TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
                //            outputSet.dump();

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                rewriter.rewrite(byteSource, baos, outputSet);
                byte bytes[] = baos.toByteArray();
View Full Code Here

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

    }

    public TiffOutputSet getOutputSet() throws ImageWriteException
    {
        int byteOrder = contents.header.byteOrder;
        TiffOutputSet result = new TiffOutputSet(byteOrder);

        ArrayList srcDirs = getDirectories();
        for (int i = 0; i < srcDirs.size(); i++)
        {
            TiffImageMetadata.Directory srcDir = (TiffImageMetadata.Directory) srcDirs
                    .get(i);

            if (null != result.findDirectory(srcDir.type))
            {
                // Certain cameras right directories more than once.
                // This is a bug.
                // Ignore second directory of a given type.
                continue;
            }

            TiffOutputDirectory outputDirectory = srcDir
                    .getOutputDirectory(byteOrder);
            result.addDirectory(outputDirectory);
        }

        return result;
    }
View Full Code Here

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

    final private ExifRewriter rewriter = new ExifRewriter();

    static TiffOutputSet getExif(File jpegImageFile)
            throws IOException, ImageReadException, ImageWriteException{
        TiffImageMetadata exif = SanselanExifReader.getExif(jpegImageFile);
        TiffOutputSet outputSet = null;
        if (null != exif) {
            outputSet = exif.getOutputSet();
        }
        // if file does not contain any exif metadata, we create an empty
        // set of exif metadata.
        if (null == outputSet){
            outputSet = new TiffOutputSet();
        }
        return outputSet;
    }
View Full Code Here

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

    @see #isAlwaysOverwrite
    **/
    @Override
    public boolean writeExifGpsInfo(File jpeg, Wpt wpt, boolean overwrite){
        try{
            TiffOutputSet outputSet = SanselanExifWriter.getExif(jpeg);
            outputSet.setGPSInDegrees(wpt.getLon().doubleValue(), wpt.getLat().doubleValue());
            TiffOutputDirectory gpsIfd = outputSet.getGPSDirectory();
            TiffOutputField field;
            final int byteOrder = outputSet.byteOrder;

            /* version */
            field = makeField(
View Full Code Here

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

    logger
        .log(Level.FINE, "writing EXIF data of "
            + file.getAbsolutePath());

    /* create the TiffOutputSet with all existing EXIF data */
    TiffOutputSet exifTags = new TiffOutputSet();

    /* load old JPEG picture and existing EXIF data */
    JpegImageMetadata jpegMetadata = null;
    try {
      jpegMetadata = (JpegImageMetadata) Sanselan.getMetadata(file);
    } catch (ImageReadException ire) {
      /* do nothing */
      logger.log(Level.INFO, "error while preparing meta data writing "
          + "(maybe picture contains no meta data)", ire);
    }

    /* check whether meta data exist */
    if (jpegMetadata != null
        && jpegMetadata.getExif() != null
        && (!(file instanceof geodress.model.Picture) || ((Picture) file)
            .getAddress().getStatus() != Address.STATUS_DEFAULT)) {
      try {
        exifTags = jpegMetadata.getExif().getOutputSet();
      } catch (ImageWriteException iwe) {
        /* do nothing */
        logger.log(Level.INFO,
            "error while preparing meta data writing", iwe);
      }

      /* iterate all fields to save and store them into the TiffOutputSet */
      for (TagInfo field : saveMap.keySet()) {
        /* remove the field if it already exists */
        TiffOutputField metadataField = exifTags.findField(field);
        if (metadataField != null) {
          exifTags.removeField(field);
        }

        TiffOutputField outputField = new TiffOutputField(field.tag,
            field, TiffFieldTypeConstants.FIELD_TYPE_ASCII, saveMap
                .get(field).length(), saveMap.get(field)
                .getBytes());
        try {
          exifTags.getOrCreateExifDirectory().add(outputField);
        } catch (ImageWriteException iwe) {
          logger.log(Level.WARNING, "error while writing EXIF data",
              iwe);
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.