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


Java ExifTagConstants类代码示例

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


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

示例1: getTiffValueDate

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
private LocalDateTime getTiffValueDate(final TiffImageMetadata tiffMetadata) {

		try {

			final TiffField exifDate = tiffMetadata.findField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, true);

			if (exifDate != null) {
				return LocalDateTime.parse(exifDate.getStringValue(), _dtParser);
			}

			final TiffField date = tiffMetadata.findField(TiffTagConstants.TIFF_TAG_DATE_TIME, true);
			if (date != null) {
				return LocalDateTime.parse(date.getStringValue(), _dtParser);
			}

		} catch (final Exception e) {
			// ignore
		}

		return null;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:22,代码来源:Photo.java

示例2: makeMergedTagList

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
private static List<TagInfo> makeMergedTagList() {
    final ArrayList<TagInfo> result = new ArrayList<>();
    result.addAll(AdobePageMaker6TagConstants.ALL_ADOBE_PAGEMAKER_6_TAGS);
    result.addAll(AdobePhotoshopTagConstants.ALL_ADOBE_PHOTOSHOP_TAGS);
    result.addAll(AliasSketchbookProTagConstants.ALL_ALIAS_SKETCHBOOK_PRO_TAGS);
    result.addAll(DcfTagConstants.ALL_DCF_TAGS);
    result.addAll(DngTagConstants.ALL_DNG_TAGS);
    result.addAll(ExifTagConstants.ALL_EXIF_TAGS);
    result.addAll(GeoTiffTagConstants.ALL_GEO_TIFF_TAGS);
    result.addAll(GdalLibraryTagConstants.ALL_GDAL_LIBRARY_TAGS);
    result.addAll(GpsTagConstants.ALL_GPS_TAGS);
    result.addAll(HylaFaxTagConstants.ALL_HYLAFAX_TAGS);
    result.addAll(MicrosoftTagConstants.ALL_MICROSOFT_TAGS);
    result.addAll(MicrosoftHdPhotoTagConstants.ALL_MICROSOFT_HD_PHOTO_TAGS);
    result.addAll(MolecularDynamicsGelTagConstants.ALL_MOLECULAR_DYNAMICS_GEL_TAGS);
    result.addAll(OceScanjobTagConstants.ALL_OCE_SCANJOB_TAGS);
    result.addAll(Rfc2301TagConstants.ALL_RFC_2301_TAGS);
    result.addAll(Tiff4TagConstants.ALL_TIFF_4_TAGS);
    result.addAll(TiffEpTagConstants.ALL_TIFF_EP_TAGS);
    result.addAll(TiffTagConstants.ALL_TIFF_TAGS);
    result.addAll(WangTagConstants.ALL_WANG_TAGS);

    return Collections.unmodifiableList(result);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:25,代码来源:TiffTags.java

示例3: checkField

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
@Override
protected void checkField(final File imageFile, final TiffField field)
        throws IOException, ImageReadException, ImageWriteException {
    if (field.getTag() == ExifTagConstants.EXIF_TAG_USER_COMMENT.tag) {
        // do nothing
    } else if (field.getTag() == GpsTagConstants.GPS_TAG_GPS_PROCESSING_METHOD.tag
            && field.getDirectoryType() == TiffDirectoryType.EXIF_DIRECTORY_GPS.directoryType) {
            // do nothing
    } else if (field.getTag() == GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION.tag
            && field.getDirectoryType() == TiffDirectoryType.EXIF_DIRECTORY_GPS.directoryType) {
            // do nothing
    } else {
        return;
    }

    try {
        final Object textFieldValue = field.getValue();
        Assert.assertNotNull(textFieldValue);
        // TODO what else to assert?
    } catch (final ImageReadException e) {
        Debug.debug("imageFile", imageFile.getAbsoluteFile());
        Debug.debug(e);
        throw e;
    }

}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:27,代码来源:TextFieldTest.java

示例4: checkField

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
@Override
protected void checkField(final File imageFile, final TiffField field)
        throws IOException, ImageReadException, ImageWriteException {
    if (field.getTag() != ExifTagConstants.EXIF_TAG_MAKER_NOTE.tag) {
        return;
    }

    Debug.debug("imageFile: " + imageFile);
    Debug.debug("field: " + field);
    Debug.debug("type: " + field.getClass().getSimpleName());

    Debug.debug("field: " + field.getTag());
    Debug.debug("field: " + field.getTagInfo());
    Debug.debug("length: " + field.getCount());
    Debug.debug("fieldType: " + field.getFieldType());
    // Debug.debug("field", Debug.getType(field));
    Debug.debug();

    // TODO assert something

}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:22,代码来源:MakerNoteFieldTest.java

示例5: readDate

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
private void readDate(JpegImageMetadata input, PhotoMetadata output) {
    LOGGER.debug("reading date from metadata");
    TiffField field = input
            .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    if (field == null) {
        LOGGER.debug("metadata contains no date");
        return;
    }
    String dateString = field.getValueDescription();
    dateString = dateString
            .substring(1, dateString.length() - 1); // remove enclosing single quotes
    output.setDatetime(DATE_FORMATTER.parse(dateString, LocalDateTime::from));
    LOGGER.debug("read date as {}", output.getDatetime());
}
 
开发者ID:travelimg,项目名称:travelimg,代码行数:15,代码来源:JpegSerializer.java

示例6: getExifValueDate

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
/**
	 * Date/Time
	 * 
	 * @param jpegMetadata
	 * @param file
	 * @return
	 */
	private LocalDateTime getExifValueDate(final JpegImageMetadata jpegMetadata) {

//		/*
//		 * !!! time is not correct, maybe it is the time when the GPS signal was
//		 * received !!!
//		 */
//		printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_TIME_STAMP);

		try {

			final TiffField exifDate = jpegMetadata.findEXIFValueWithExactMatch(//
					ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);

			if (exifDate != null) {
				return LocalDateTime.parse(exifDate.getStringValue(), _dtParser);
			}

			final TiffField tiffDate = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_DATE_TIME);

			if (tiffDate != null) {
				return LocalDateTime.parse(tiffDate.getStringValue(), _dtParser);
			}

		} catch (final Exception e) {
			// ignore
		}

		return null;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:37,代码来源:Photo.java

示例7: getTimeStampFromImage

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
/**
 * @param jpegMetadata
 * 		Pass the metadata of the image.
 * @return
 * 		Capture timestamp of the image from the metadata. {@link ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL} is used to get the value.
 * @throws ParseException
 */
public static Long getTimeStampFromImage(final JpegImageMetadata jpegMetadata) throws ParseException{
	final TagInfo tagInfo = ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL;
	final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
	String dateOfCaptureString = field.getValueDescription();
	SimpleDateFormat sdf = new SimpleDateFormat("''yyyy:MM:dd hh:mm:ss''");
	Date dateOfCapture = sdf.parse(dateOfCaptureString);
	return dateOfCapture.getTime();
}
 
开发者ID:codailama,项目名称:GeoTagPhotos,代码行数:16,代码来源:EXIFUtils.java

示例8: getTimeTaken

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
private static Instant getTimeTaken(final TiffImageMetadata exif,
        final File file) {
    Instant instant = null;
    if (exif != null) {
        try {
            final String[] dateTimeOriginal = exif.getFieldValue(
                    ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
            if (dateTimeOriginal.length == 1
                    && dateTimeOriginal[0].matches(
                            "\\d{4}\\:\\d{2}:\\d{2}\\s\\d{2}:\\d{2}:\\d{2}")) {
                final String[] split = dateTimeOriginal[0].split("\\s");
                final String dateString = split[0];
                final String timeString = split[1];
                final String[] dateSplit = dateString.split("\\:");
                final int year = Integer.parseInt(dateSplit[0]);
                final int month = Integer.parseInt(dateSplit[1]);
                final int day = Integer.parseInt(dateSplit[2]);
                final String[] timeSplit = timeString.split("\\:");
                final int hour = Integer.parseInt(timeSplit[0]);
                final int minute = Integer.parseInt(timeSplit[1]);
                final int second = Integer.parseInt(timeSplit[2]);
                final LocalDateTime ldt = LocalDateTime.of(
                        year, month, day, hour, minute, second);
                instant = ldt.toInstant(ZoneOffset.ofHoursMinutes(0, 0));
            } else {
                log(Level.WARNING, String.format(
                        "unknown date format in file %s", file.getPath()));
            }
        }
        catch (ImageReadException ex) {
            Logger.getLogger(PhotoLoader.class.getName()).
                    log(Level.SEVERE, null, ex);
        }
    }
    return instant;
}
 
开发者ID:consulion,项目名称:jeotag,代码行数:37,代码来源:PhotoLoader.java

示例9: testTagIntegrity

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
@Test
public void testTagIntegrity() {
    verifyFields(AdobePageMaker6TagConstants.class,
            AdobePageMaker6TagConstants.ALL_ADOBE_PAGEMAKER_6_TAGS);
    verifyFields(AdobePhotoshopTagConstants.class,
            AdobePhotoshopTagConstants.ALL_ADOBE_PHOTOSHOP_TAGS);
    verifyFields(AliasSketchbookProTagConstants.class,
            AliasSketchbookProTagConstants.ALL_ALIAS_SKETCHBOOK_PRO_TAGS);
    verifyFields(DcfTagConstants.class, DcfTagConstants.ALL_DCF_TAGS);
    verifyFields(DngTagConstants.class, DngTagConstants.ALL_DNG_TAGS);
    verifyFields(ExifTagConstants.class, ExifTagConstants.ALL_EXIF_TAGS);
    verifyFields(GeoTiffTagConstants.class,
            GeoTiffTagConstants.ALL_GEO_TIFF_TAGS);
    verifyFields(GdalLibraryTagConstants.class,
            GdalLibraryTagConstants.ALL_GDAL_LIBRARY_TAGS);
    verifyFields(GpsTagConstants.class, GpsTagConstants.ALL_GPS_TAGS);
    verifyFields(
            MolecularDynamicsGelTagConstants.class,
            MolecularDynamicsGelTagConstants.ALL_MOLECULAR_DYNAMICS_GEL_TAGS);
    verifyFields(MicrosoftTagConstants.class,
            MicrosoftTagConstants.ALL_MICROSOFT_TAGS);
    verifyFields(MicrosoftHdPhotoTagConstants.class,
            MicrosoftHdPhotoTagConstants.ALL_MICROSOFT_HD_PHOTO_TAGS);
    verifyFields(OceScanjobTagConstants.class,
            OceScanjobTagConstants.ALL_OCE_SCANJOB_TAGS);
    verifyFields(Rfc2301TagConstants.class,
            Rfc2301TagConstants.ALL_RFC_2301_TAGS);
    verifyFields(Tiff4TagConstants.class, Tiff4TagConstants.ALL_TIFF_4_TAGS);
    verifyFields(TiffEpTagConstants.class,
            TiffEpTagConstants.ALL_TIFF_EP_TAGS);
    verifyFields(TiffTagConstants.class, TiffTagConstants.ALL_TIFF_TAGS);
    verifyFields(WangTagConstants.class, WangTagConstants.ALL_WANG_TAGS);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:34,代码来源:TiffTagIntegrityTest.java

示例10: update

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的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

示例11: readMetaData

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
private void readMetaData(JpegImageMetadata input, PhotoMetadata result) {
    String tags = "";
    if (input.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_USER_COMMENT) != null) {
        tags = input.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_USER_COMMENT)
                .getValueDescription();
        // no tags from our programm
        if (!tags.contains("travelimg"))
            return;
        LOGGER.debug("Tags in exif found: " + tags);
        tags = tags.replace("'", "");
    } else {
        return;
    }
    String[] tagArray = tags.split("/");
    for (String element : tagArray) {
        if (element.equals("travelimg"))
            continue;

        // journeys
        if (element.contains("journey")) {
            String[] tempJourney = element.split("\\|");
            LocalDateTime startDate = LocalDateTime.parse(tempJourney[2], DATE_FORMATTER);
            LocalDateTime endDate = LocalDateTime.parse(tempJourney[3], DATE_FORMATTER);
            result.setJourney(new Journey(null, tempJourney[1], startDate, endDate));
            continue;
        }

        // places
        if (element.contains("place")) {
            String[] tempPlace = element.split("\\|");
            result.setPlace(
                    new Place(0, tempPlace[1], tempPlace[2], Double.parseDouble(tempPlace[3]),
                            Double.parseDouble(tempPlace[4])));
            continue;
        }

        // rating
        if (element.contains("rating")) {
            String[] tempRating = element.split("\\|");
            result.setRating(Rating.valueOf(tempRating[1]));
            continue;
        }

        // photographer
        if (element.contains("photographer")) {
            String[] tempPhotographer = element.split("\\|");
            result.setPhotographer(new Photographer(null, tempPhotographer[1]));
            continue;
        }

        // tags
        if (!element.trim().isEmpty()) {
            result.getTags().add(new Tag(null, element));
        }
    }

}
 
开发者ID:travelimg,项目名称:travelimg,代码行数:58,代码来源:JpegSerializer.java

示例12: getExif

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
@Override
public Exif getExif(Photo photo) throws ServiceException {
    File file = new File(photo.getPath());
    String exposure = "not available";
    double aperture = 0.0;
    double focalLength = 0.0;
    int iso = 0;
    boolean flash = false;
    String make = "not available";
    String model = "not available";
    double altitude = 0.0;

    try {
        final ImageMetadata metadata = Imaging.getMetadata(file);
        final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME)
                != null) {
            exposure = jpegMetadata
                    .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME)
                    .getValueDescription().split(" ")[0];
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE)
                != null) {
            aperture = jpegMetadata
                    .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE)
                    .getDoubleValue();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH)
                != null) {
            focalLength = jpegMetadata
                    .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH)
                    .getDoubleValue();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO) != null) {
            iso = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO)
                    .getIntValue();
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH) != null) {
            flash = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH)
                    .getIntValue() != 0;
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE) != null) {
            make = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE)
                    .getValueDescription();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL) != null) {
            model = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL)
                    .getValueDescription();
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE)
                != null) {
            altitude = jpegMetadata
                    .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE)
                    .getDoubleValue();
        }

        return new Exif(photo.getId(), exposure, aperture, focalLength, iso, flash, make, model,
                altitude);
    } catch (IOException | ImageReadException e) {
        throw new ServiceException(e.getMessage(), e);
    }
}
 
开发者ID:travelimg,项目名称:travelimg,代码行数:68,代码来源:ExifServiceImpl.java

示例13: write

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的package包/类
@Override
public void write(final OutputStream os, final TiffOutputSet outputSet)
        throws IOException, ImageWriteException {
    // There are some fields whose address in the file must not change,
    // unless of course their value is changed. 
    final Map<Integer, TiffOutputField> frozenFields = new HashMap<>();
    final TiffOutputField makerNoteField = outputSet.findField(ExifTagConstants.EXIF_TAG_MAKER_NOTE);
    if (makerNoteField != null && makerNoteField.getSeperateValue() != null) {
        frozenFields.put(ExifTagConstants.EXIF_TAG_MAKER_NOTE.tag, makerNoteField);
    }
    final List<TiffElement> analysis = analyzeOldTiff(frozenFields);
    final int oldLength = exifBytes.length;
    if (analysis.isEmpty()) {
        throw new ImageWriteException("Couldn't analyze old tiff data.");
    } else if (analysis.size() == 1) {
        final TiffElement onlyElement = analysis.get(0);
        if (onlyElement.offset == TIFF_HEADER_SIZE
                && onlyElement.offset + onlyElement.length
                        + TIFF_HEADER_SIZE == oldLength) {
            // no gaps in old data, safe to complete overwrite.
            new TiffImageWriterLossy(byteOrder).write(os, outputSet);
            return;
        }
    }
    final Map<Long, TiffOutputField> frozenFieldOffsets = new HashMap<>();
    for (final Map.Entry<Integer, TiffOutputField> entry : frozenFields.entrySet()) {
        final TiffOutputField frozenField = entry.getValue();
        if (frozenField.getSeperateValue().getOffset() != TiffOutputItem.UNDEFINED_VALUE) {
            frozenFieldOffsets.put(frozenField.getSeperateValue().getOffset(), frozenField);
        }
    }

    final TiffOutputSummary outputSummary = validateDirectories(outputSet);

    final List<TiffOutputItem> allOutputItems = outputSet.getOutputItems(outputSummary);
    final List<TiffOutputItem> outputItems = new ArrayList<>();
    for (final TiffOutputItem outputItem : allOutputItems) {
        if (!frozenFieldOffsets.containsKey(outputItem.getOffset())) {
            outputItems.add(outputItem);
        }
    }

    final long outputLength = updateOffsetsStep(analysis, outputItems);

    outputSummary.updateOffsets(byteOrder);

    writeStep(os, outputSet, analysis, outputItems, outputLength);

}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:50,代码来源:TiffImageWriterLossless.java

示例14: removeExifTag

import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; //导入依赖的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.tiff.constants.ExifTagConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。