本文整理汇总了Java中org.apache.commons.imaging.formats.tiff.write.TiffOutputSet类的典型用法代码示例。如果您正苦于以下问题:Java TiffOutputSet类的具体用法?Java TiffOutputSet怎么用?Java TiffOutputSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TiffOutputSet类属于org.apache.commons.imaging.formats.tiff.write包,在下文中一共展示了TiffOutputSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getOutputSet
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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: setExifGPSTag
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例3: getOutputSet
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例4: copyExifOrientation
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例5: updateExifMetadataLossless
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
/**
* Reads a Jpeg image, replaces the EXIF metadata and writes the result to a
* stream.
* <p>
* Note that this uses the "Lossless" approach - in order to preserve data
* embedded in the EXIF segment that it can't parse (such as Maker Notes),
* this algorithm avoids overwriting any part of the original segment that
* it couldn't parse. This can cause the EXIF segment to grow with each
* update, which is a serious issue, since all EXIF data must fit in a
* single APP1 segment of the Jpeg image.
* <p>
*
* @param byteSource
* ByteSource containing Jpeg image data.
* @param os
* OutputStream to write the image to.
* @param outputSet
* TiffOutputSet containing the EXIF data to write.
*/
public void updateExifMetadataLossless(final ByteSource byteSource,
final OutputStream os, final TiffOutputSet outputSet)
throws ImageReadException, IOException, ImageWriteException {
// List outputDirectories = outputSet.getDirectories();
final JFIFPieces jfifPieces = analyzeJFIF(byteSource);
final List<JFIFPiece> pieces = jfifPieces.pieces;
TiffImageWriterBase writer;
// Just use first APP1 segment for now.
// Multiple APP1 segments are rare and poorly supported.
if (jfifPieces.exifPieces.size() > 0) {
JFIFPieceSegment exifPiece = null;
exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
byte[] exifBytes = exifPiece.segmentData;
exifBytes = remainingBytes("trimmed exif bytes", exifBytes, 6);
writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes);
} else {
writer = new TiffImageWriterLossy(outputSet.byteOrder);
}
final boolean includeEXIFPrefix = true;
final byte[] newBytes = writeExifSegment(writer, outputSet, includeEXIFPrefix);
writeSegmentsReplacingExif(os, pieces, newBytes);
}
开发者ID:windwardadmin,项目名称:android-awt,代码行数:48,代码来源:ExifRewriter.java
示例6: writeExifSegment
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
private byte[] writeExifSegment(final TiffImageWriterBase writer,
final TiffOutputSet outputSet, final boolean includeEXIFPrefix)
throws IOException, ImageWriteException {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
if (includeEXIFPrefix) {
JpegConstants.EXIF_IDENTIFIER_CODE.writeTo(os);
os.write(0);
os.write(0);
}
writer.write(os, outputSet);
return os.toByteArray();
}
开发者ID:windwardadmin,项目名称:android-awt,代码行数:16,代码来源:ExifRewriter.java
示例7: testWrite
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例8: testRewrite
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例9: testRewriteLossy
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
@Test
public void testRewriteLossy() throws Exception {
final Rewriter rewriter = new Rewriter() {
@Override
public void rewrite(final ByteSource byteSource, final OutputStream os,
final TiffOutputSet outputSet) throws ImageReadException,
IOException, ImageWriteException {
new ExifRewriter().updateExifMetadataLossy(byteSource, os,
outputSet);
}
};
rewrite(rewriter, "lossy");
}
开发者ID:apache,项目名称:commons-imaging,代码行数:15,代码来源:ExifRewriteTest.java
示例10: testRewriteLossless
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
@Test
public void testRewriteLossless() throws Exception {
final Rewriter rewriter = new Rewriter() {
@Override
public void rewrite(final ByteSource byteSource, final OutputStream os,
final TiffOutputSet outputSet) throws ImageReadException,
IOException, ImageWriteException {
new ExifRewriter().updateExifMetadataLossless(byteSource, os,
outputSet);
}
};
rewrite(rewriter, "lossless");
}
开发者ID:apache,项目名称:commons-imaging,代码行数:15,代码来源:ExifRewriteTest.java
示例11: update
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例12: rewrite
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
public void rewrite(ByteSource byteSource, OutputStream os,
TiffOutputSet outputSet) throws ImageReadException,
IOException, ImageWriteException;
开发者ID:apache,项目名称:commons-imaging,代码行数:4,代码来源:ExifRewriteTest.java
示例13: testReadWriteTags
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例14: removeExifTag
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的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
示例15: updateExifMetadataLossy
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; //导入依赖的package包/类
/**
* Reads a Jpeg image, replaces the EXIF metadata and writes the result to a
* stream.
* <p>
* Note that this uses the "Lossy" approach - the algorithm overwrites the
* entire EXIF segment, ignoring the possibility that it may be discarding
* data it couldn't parse (such as Maker Notes).
* <p>
*
* @param src
* Byte array containing Jpeg image data.
* @param os
* OutputStream to write the image to.
* @param outputSet
* TiffOutputSet containing the EXIF data to write.
*/
public void updateExifMetadataLossy(final byte[] src, final OutputStream os,
final TiffOutputSet outputSet) throws ImageReadException, IOException,
ImageWriteException {
final ByteSource byteSource = new ByteSourceArray(src);
updateExifMetadataLossy(byteSource, os, outputSet);
}
开发者ID:windwardadmin,项目名称:android-awt,代码行数:23,代码来源:ExifRewriter.java
注:本文中的org.apache.commons.imaging.formats.tiff.write.TiffOutputSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论