本文整理汇总了Java中org.apache.commons.imaging.formats.tiff.TiffImageMetadata.getOutputSet方法的典型用法代码示例。如果您正苦于以下问题:Java TiffImageMetadata.getOutputSet方法的具体用法?Java TiffImageMetadata.getOutputSet怎么用?Java TiffImageMetadata.getOutputSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.imaging.formats.tiff.TiffImageMetadata
的用法示例。
在下文中一共展示了TiffImageMetadata.getOutputSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRewrite
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; //导入方法依赖的package包/类
@Test
public void testRewrite() throws Exception {
final byte[] imageWithExif = cleanImage(getImageWithExifData());
final TiffImageMetadata metadata = toTiffMetadata(Imaging.getMetadata(imageWithExif));
final ExifRewriter rewriter = new ExifRewriter();
final TiffOutputSet outputSet = metadata.getOutputSet();
final TiffOutputDirectory root = outputSet.getOrCreateRootDirectory();
// In Windows these will also hide XP fields:
root.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION);
root.removeField(TiffTagConstants.TIFF_TAG_ARTIST);
// Duplicates can be a problem:
root.removeField(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR);
root.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, AUTHOR);
root.removeField(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT);
root.add(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT, COMMENT);
root.removeField(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT);
root.add(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT, SUBJECT);
root.removeField(MicrosoftTagConstants.EXIF_TAG_XPTITLE);
root.add(MicrosoftTagConstants.EXIF_TAG_XPTITLE, TITLE);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
rewriter.updateExifMetadataLossy(imageWithExif, baos, outputSet);
checkFields(baos.toByteArray());
}
示例2: update
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; //导入方法依赖的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");
}
示例3: removeExifTag
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; //导入方法依赖的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);
}
}