本文整理汇总了Java中org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory类的典型用法代码示例。如果您正苦于以下问题:Java TiffOutputDirectory类的具体用法?Java TiffOutputDirectory怎么用?Java TiffOutputDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TiffOutputDirectory类属于org.apache.commons.imaging.formats.tiff.write包,在下文中一共展示了TiffOutputDirectory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getOutputSet
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
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;
}
开发者ID:windwardadmin,项目名称:android-awt,代码行数:23,代码来源:TiffImageMetadata.java
示例2: getOutputSet
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
public TiffOutputSet getOutputSet() throws ImageWriteException {
final ByteOrder byteOrder = contents.header.byteOrder;
final TiffOutputSet result = new TiffOutputSet(byteOrder);
final List<? extends ImageMetadataItem> srcDirs = getDirectories();
for (final ImageMetadataItem 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;
}
开发者ID:apache,项目名称:commons-imaging,代码行数:22,代码来源:TiffImageMetadata.java
示例3: copyExifOrientation
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的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
示例4: testWrite
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
@Test
public void testWrite() throws Exception {
final BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
final TiffOutputSet exifSet = new TiffOutputSet();
final TiffOutputDirectory root = exifSet.getOrCreateRootDirectory();
root.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, AUTHOR);
root.add(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT, COMMENT);
root.add(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT, SUBJECT);
root.add(MicrosoftTagConstants.EXIF_TAG_XPTITLE, TITLE);
final Map<String, Object> params = new TreeMap<>();
params.put(ImagingConstants.PARAM_KEY_EXIF, exifSet);
final byte[] bytes = Imaging.writeImageToBytes(image, ImageFormats.TIFF, params);
checkFields(bytes);
}
开发者ID:apache,项目名称:commons-imaging,代码行数:15,代码来源:MicrosoftTagTest.java
示例5: testRewrite
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的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());
}
开发者ID:apache,项目名称:commons-imaging,代码行数:31,代码来源:MicrosoftTagTest.java
示例6: update
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的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
示例7: getOutputDirectory
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
public TiffOutputDirectory getOutputDirectory(final ByteOrder byteOrder)
throws ImageWriteException {
try {
final TiffOutputDirectory dstDir = new TiffOutputDirectory(type,
byteOrder);
final List<? extends IImageMetadataItem> entries = getItems();
for (IImageMetadataItem entry : entries) {
final TiffImageMetadata.Item item = (TiffImageMetadata.Item) entry;
final TiffField srcField = item.getTiffField();
if (null != dstDir.findField(srcField.getTag())) {
// ignore duplicate tags in a directory.
continue;
} else if (srcField.getTagInfo().isOffset()) {
// ignore offset fields.
continue;
}
final TagInfo tagInfo = srcField.getTagInfo();
final FieldType fieldType = srcField.getFieldType();
// byte bytes[] = srcField.fieldType.getRawBytes(srcField);
// Debug.debug("tagInfo", tagInfo);
final Object value = srcField.getValue();
// Debug.debug("value", Debug.getType(value));
final byte[] bytes = tagInfo.encodeValue(fieldType, value,
byteOrder);
// if (tagInfo.isUnknown())
// Debug.debug(
// "\t" + "unknown tag(0x"
// + Integer.toHexString(srcField.tag)
// + ") bytes", bytes);
final int count = bytes.length / fieldType.getSize();
final TiffOutputField dstField = new TiffOutputField(
srcField.getTag(), tagInfo, fieldType, count, bytes);
dstField.setSortHint(srcField.getSortHint());
dstDir.add(dstField);
}
dstDir.setTiffImageData(getTiffImageData());
dstDir.setJpegImageData(getJpegImageData());
return dstDir;
} catch (final ImageReadException e) {
throw new ImageWriteException(e.getMessage(), e);
}
}
开发者ID:windwardadmin,项目名称:android-awt,代码行数:54,代码来源:TiffImageMetadata.java
示例8: getOutputDirectory
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
public TiffOutputDirectory getOutputDirectory(final ByteOrder byteOrder)
throws ImageWriteException {
try {
final TiffOutputDirectory dstDir = new TiffOutputDirectory(type,
byteOrder);
final List<? extends ImageMetadataItem> entries = getItems();
for (final ImageMetadataItem entry : entries) {
final TiffMetadataItem item = (TiffMetadataItem) entry;
final TiffField srcField = item.getTiffField();
if (null != dstDir.findField(srcField.getTag())) {
// ignore duplicate tags in a directory.
continue;
} else if (srcField.getTagInfo().isOffset()) {
// ignore offset fields.
continue;
}
final TagInfo tagInfo = srcField.getTagInfo();
final FieldType fieldType = srcField.getFieldType();
// byte bytes[] = srcField.fieldType.getRawBytes(srcField);
// Debug.debug("tagInfo", tagInfo);
final Object value = srcField.getValue();
// Debug.debug("value", Debug.getType(value));
final byte[] bytes = tagInfo.encodeValue(fieldType, value,
byteOrder);
// if (tagInfo.isUnknown())
// Debug.debug(
// "\t" + "unknown tag(0x"
// + Integer.toHexString(srcField.tag)
// + ") bytes", bytes);
final int count = bytes.length / fieldType.getSize();
final TiffOutputField dstField = new TiffOutputField(
srcField.getTag(), tagInfo, fieldType, count, bytes);
dstField.setSortHint(srcField.getSortHint());
dstDir.add(dstField);
}
dstDir.setTiffImageData(getTiffImageData());
dstDir.setJpegImageData(getJpegImageData());
return dstDir;
} catch (final ImageReadException e) {
throw new ImageWriteException(e.getMessage(), e);
}
}
开发者ID:apache,项目名称:commons-imaging,代码行数:54,代码来源:TiffImageMetadata.java
示例9: testReadWriteTags
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的package包/类
@Test
public void testReadWriteTags() throws ImageWriteException, ImageReadException, IOException {
final String description = "A pretty picture";
final short page = 1;
final RationalNumber twoThirds = new RationalNumber(2, 3);
final int t4Options = 0;
final int width = 10;
final short height = 10;
final String area = "A good area";
final float widthRes = 2.2f;
final double geoDoubleParams = -8.4;
final TiffOutputSet set = new TiffOutputSet();
final TiffOutputDirectory dir = set.getOrCreateRootDirectory();
dir.add(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION, description);
dir.add(TiffTagConstants.TIFF_TAG_PAGE_NUMBER, page, page);
dir.add(TiffTagConstants.TIFF_TAG_YRESOLUTION, twoThirds);
dir.add(TiffTagConstants.TIFF_TAG_T4_OPTIONS, t4Options);
dir.add(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, width);
dir.add(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, new short[]{height});
dir.add(GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION, area);
dir.add(MicrosoftHdPhotoTagConstants.EXIF_TAG_WIDTH_RESOLUTION, widthRes);
dir.add(GeoTiffTagConstants.EXIF_TAG_GEO_DOUBLE_PARAMS_TAG, geoDoubleParams);
final TiffImageWriterLossy writer = new TiffImageWriterLossy();
final ByteArrayOutputStream tiff = new ByteArrayOutputStream();
writer.write(tiff, set);
final TiffReader reader = new TiffReader(true);
final Map<String, Object> params = new TreeMap<>();
final FormatCompliance formatCompliance = new FormatCompliance("");
final TiffContents contents = reader.readFirstDirectory(new ByteSourceArray(tiff.toByteArray()), params, true, formatCompliance);
final TiffDirectory rootDir = contents.directories.get(0);
assertEquals(description, rootDir.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION));
assertEquals(page, rootDir.getFieldValue(TiffTagConstants.TIFF_TAG_PAGE_NUMBER, true)[0]);
final RationalNumber yRes = rootDir.getFieldValue(TiffTagConstants.TIFF_TAG_YRESOLUTION);
assertEquals(twoThirds.numerator, yRes.numerator);
assertEquals(twoThirds.divisor, yRes.divisor);
assertEquals(t4Options, rootDir.getFieldValue(TiffTagConstants.TIFF_TAG_T4_OPTIONS));
assertEquals(width, rootDir.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH));
assertEquals(width, rootDir.getSingleFieldValue(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH));
assertEquals(area, rootDir.getFieldValue(GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION, true));
assertEquals(widthRes, rootDir.getFieldValue(MicrosoftHdPhotoTagConstants.EXIF_TAG_WIDTH_RESOLUTION), 0.0);
assertEquals(geoDoubleParams, rootDir.getFieldValue(GeoTiffTagConstants.EXIF_TAG_GEO_DOUBLE_PARAMS_TAG, true)[0], 0.0);
}
开发者ID:apache,项目名称:commons-imaging,代码行数:46,代码来源:TiffReadWriteTagsTest.java
示例10: removeExifTag
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; //导入依赖的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.write.TiffOutputDirectory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论