当前位置: 首页>>代码示例>>Java>>正文


Java ExifRewriter类代码示例

本文整理汇总了Java中org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter的典型用法代码示例。如果您正苦于以下问题:Java ExifRewriter类的具体用法?Java ExifRewriter怎么用?Java ExifRewriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExifRewriter类属于org.apache.commons.imaging.formats.jpeg.exif包,在下文中一共展示了ExifRewriter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setExifGPSTag

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
/**
 * This method sets the EXIF the of the JPEG file and outputs it to given directory.
 * @param jpegImageFile
 * 		Input jpeg file.
 * @param dst
 * 		output jpeg file.
 * @param longitude
 * 		Longitude to be tagged.
 * @param latitude
 * 	 	Latitude to be tagged.
 * @throws IOException
 * @throws ImageReadException
 * @throws ImageWriteException
 */
public static void setExifGPSTag(final File jpegImageFile, final File dst, final double longitude, final double latitude) throws IOException,
ImageReadException, ImageWriteException {
	OutputStream os = null;
	boolean canThrow = false;
	try {

		final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
		final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
		TiffOutputSet outputSet = setTiffOutputSet(jpegMetadata, longitude, latitude);
		os = new FileOutputStream(dst);
		os = new BufferedOutputStream(os);
		new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet);
		canThrow = true;
	} finally {
		IoUtils.closeQuietly(canThrow, os);
	}
}
 
开发者ID:codailama,项目名称:GeoTagPhotos,代码行数:32,代码来源:EXIFUtils.java

示例2: copyExifOrientation

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
/**
 * This method will copy the Exif "orientation" information to the resulting image, if the
 * original image contains this data too.
 *
 * @param sourceImage
 *            The source image.
 * @param result
 *            The original result.
 * @return The new result containing the Exif orientation.
 */
public static byte[] copyExifOrientation(byte[] sourceImage, byte[] result) {
    try {
        ImageMetadata imageMetadata = Imaging.getMetadata(sourceImage);
        if (imageMetadata == null) {
            return result;
        }
        List<? extends ImageMetadata.ImageMetadataItem> metadataItems = imageMetadata
                .getItems();
        for (ImageMetadata.ImageMetadataItem metadataItem : metadataItems) {
            if (metadataItem instanceof TiffImageMetadata.TiffMetadataItem) {
                TiffField tiffField = ((TiffImageMetadata.TiffMetadataItem) metadataItem)
                        .getTiffField();
                if (!tiffField.getTagInfo().equals(TiffTagConstants.TIFF_TAG_ORIENTATION)) {
                    continue;
                }
                Object orientationValue = tiffField.getValue();
                if (orientationValue == null) {
                    break;
                }
                TiffOutputSet outputSet = new TiffOutputSet();
                TiffOutputDirectory outputDirectory = outputSet.getOrCreateRootDirectory();
                outputDirectory.add(TiffTagConstants.TIFF_TAG_ORIENTATION,
                        ((Number) orientationValue).shortValue());
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                new ExifRewriter().updateExifMetadataLossy(result, outputStream, outputSet);
                return outputStream.toByteArray();
            }
        }
    } catch (IOException | ImageWriteException | ImageReadException e) {
        LOGGER.warn("Error reading image: {}", e.getMessage());
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:45,代码来源:ImageHelper.java

示例3: removeExifMetadata

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
public void removeExifMetadata(final File jpegImageFile, final File dst)
        throws IOException, ImageReadException, ImageWriteException {
    OutputStream os = null;
    boolean canThrow = false;
    try {
        os = new FileOutputStream(dst);
        os = new BufferedOutputStream(os);

        new ExifRewriter().removeExifMetadata(jpegImageFile, os);
        canThrow = true;
    } finally {
        IoUtils.closeQuietly(canThrow, os);
    }
}
 
开发者ID:codailama,项目名称:GeoTagPhotos,代码行数:15,代码来源:WriteExifMetadataExample.java

示例4: removeExifMetadata

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
public void removeExifMetadata(final File jpegImageFile, final File dst)
        throws IOException, ImageReadException, ImageWriteException {
    try (FileOutputStream fos = new FileOutputStream(dst);
            OutputStream os = new BufferedOutputStream(fos)) {
        new ExifRewriter().removeExifMetadata(jpegImageFile, os);
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:8,代码来源:WriteExifMetadataExample.java

示例5: update

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
@Override public void update(InputStream is, OutputStream os, PhotoMetadata metadata)
        throws DAOException {
    if (is == null)
        throw new IllegalArgumentException();
    if (os == null)
        throw new IllegalArgumentException();
    if (metadata == null)
        throw new IllegalArgumentException();
    LOGGER.debug("updating photo metadata {}", metadata);

    String tags = "travelimg";

    for (Tag element : metadata.getTags()) {
        tags += "/" + element.getName();
    }

    Rating rating = metadata.getRating();
    tags += "/rating|" + rating;

    Place place = metadata.getPlace();
    if (place != null) {
        tags += "/place|" + place.getCity() + "|" + place.getCountry() + "|" + place
                .getLatitude() + "|" + place.getLongitude();
    }

    Journey journey = metadata.getJourney();
    if (journey != null) {
        tags += "/journey|" + journey.getName() + "|" + journey.getStartDate()
                .format(DATE_FORMATTER) + "|" + journey.getEndDate().format(DATE_FORMATTER);
    }

    Photographer photographer = metadata.getPhotographer();
    if (photographer != null) {
        tags += "/photographer|" + photographer.getName();
    }

    try {
        is.mark(Integer.MAX_VALUE);
        ImageMetadata imageData = Imaging.getMetadata(is, null);
        if (imageData == null) {
            LOGGER.debug("could not find image metadata");
            throw new DAOException("No metadata found.");
        }
        if (!(imageData instanceof JpegImageMetadata)) {
            LOGGER.debug("metadata is of unknown type");
            throw new DAOException("Metadata is of unknown type.");
        }

        JpegImageMetadata jpegData = (JpegImageMetadata) imageData;
        TiffOutputSet outputSet = new TiffOutputSet();
        TiffImageMetadata exifData = jpegData.getExif();
        if (exifData != null) {
            outputSet = exifData.getOutputSet();
        }

        TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
        outputSet.setGPSInDegrees(metadata.getLongitude(), metadata.getLatitude());

        exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
        exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
                DATE_FORMATTER.format(metadata.getDatetime()));

        exifDirectory.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT);
        exifDirectory.add(ExifTagConstants.EXIF_TAG_USER_COMMENT, tags);

        is.reset();
        new ExifRewriter().updateExifMetadataLossless(is, os, outputSet);

    } catch (IOException | ImageReadException | ImageWriteException ex) {
        LOGGER.warn("failed updating metadata");
        throw new DAOException(ex);
    }

    LOGGER.debug("updated photo metadata");
}
 
开发者ID:travelimg,项目名称:travelimg,代码行数:76,代码来源:JpegSerializer.java

示例6: removeExifTag

import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; //导入依赖的package包/类
/**
 * This example illustrates how to remove a tag (if present) from EXIF
 * metadata in a JPEG file.
 * 
 * In this case, we remove the "aperture" tag from the EXIF metadata if
 * present.
 * 
 * @param jpegImageFile
 *            A source image file.
 * @param dst
 *            The output file.
 * @throws IOException
 * @throws ImageReadException
 * @throws ImageWriteException
 */
public void removeExifTag(final File jpegImageFile, final File dst) throws IOException,
        ImageReadException, ImageWriteException {
    try (FileOutputStream fos = new FileOutputStream(dst);
            OutputStream os = new BufferedOutputStream(fos)) {
        TiffOutputSet outputSet = null;

        // note that metadata might be null if no metadata is found.
        final ImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
        final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
        if (null != jpegMetadata) {
            // note that exif might be null if no Exif metadata is found.
            final 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.
            FileUtils.copyFile(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(ExifTagConstants.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.
            final TiffOutputDirectory exifDirectory = outputSet.getExifDirectory();
            if (null != exifDirectory) {
                exifDirectory.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
            }
        }

        new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
                outputSet);
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:77,代码来源:WriteExifMetadataExample.java


注:本文中的org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。