-2
A
回答
2
你可以用Apache commons imaging做到这一点。
/**
* This example illustrates how to add/update EXIF metadata in a JPEG file.
*
* @param jpegImageFile
* A source image file.
* @param dst
* The output file.
* @throws IOException
* @throws ImageReadException
* @throws ImageWriteException
*/
public void changeExifMetadata(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 file does not contain any exif metadata, we create an empty
// set of exif metadata. Otherwise, we keep all of the other
// existing tags.
if (null == outputSet) {
outputSet = new TiffOutputSet();
}
{
// Example of how to add a field/tag to the output set.
//
// Note that you should first remove the field/tag if it already
// exists in this directory, or you may end up with duplicate
// tags. See above.
//
// Certain fields/tags are expected in certain Exif directories;
// Others can occur in more than one directory (and often have a
// different meaning in different directories).
//
// TagInfo constants often contain a description of what
// directories are associated with a given tag.
//
final TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
// make sure to remove old value if present (this method will
// not fail if the tag does not exist).
exifDirectory.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
exifDirectory.add(ExifTagConstants.EXIF_TAG_APERTURE_VALUE,
new RationalNumber(3, 10));
}
{
// Example of how to add/update GPS info to output set.
// New York City
final double longitude = -74.0; // 74 degrees W (in Degrees East)
final double latitude = 40 + 43/60.0; // 40 degrees N (in Degrees
// North)
outputSet.setGPSInDegrees(longitude, latitude);
}
// printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
outputSet);
}
}
有很多的例子here
相关问题
- 1. 将GPS坐标映射到图像
- 2. 获取GPS地图的GPS坐标
- 3. 如何设置像素坐标?
- 4. 在基于GPS坐标的mapview上设置视图
- 5. 设置坐标图像查看
- 6. 如何在matlab GUI中设置坐标轴中的图像?
- 7. 如何设置OpenGl坐标?
- 8. Android Gps坐标
- 9. gps坐标+米
- 10. QuickTime GPS坐标
- 11. 坐标位置图像Android
- 12. 如何为maptoolbar的导航图标设置位置坐标?
- 13. 如何用实时GPS坐标更新标记的位置?
- 14. 地图GPS定制地板图像上的坐标
- 15. GPS坐标的默认位置
- 16. 如何设置像素坐标以匹配GFLW3中的窗口坐标
- 17. GPS坐标偏差
- 18. 移动GPS坐标
- 19. GPS坐标精度
- 20. 查询GPS坐标
- 21. 如何从像素坐标计算归一化图像坐标?
- 22. 谷歌地图上的GPS坐标
- 23. 如何从我的GPS坐标ge附近的位置?
- 24. Android - 获取GPS坐标和位置
- 25. 无法读取相机胶卷图像的GPS坐标
- 26. 如何从iPhone/Android获取GPS坐标?
- 27. 如何获取GPS坐标多边形
- 28. 如何在FlashBuilder中存储GPS坐标?
- 29. 如何绘制GPS在Matlab坐标
- 30. 如何在iOS中存储GPS坐标?