Apache Commons Imaging(EXIF):缺少标签/标签 [英] Apache Commons Imaging (EXIF): Setting tags/tags missing

查看:87
本文介绍了Apache Commons Imaging(EXIF):缺少标签/标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons Imaging

您可以在此处,其中包括作者"和艺术家"之一.库中的某个位置似乎已经存在艺术家"标记(

我尝试改用"Maker"标签:

  final TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();exifDir.removeField(ExifTagConstants.EXIF_TAG_MAKER_NOTE);exifDir.add(ExifTagConstants.EXIF_TAG_MAKER_NOTE,测试制作者"); 

但是 ExifTagConstants.EXIF_TAG_MAKER_NOTE TagInfoUndefineds 类型对于 exifDir.add 似乎无效.

我还尝试添加日期:

  exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED);exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED,"1970/01/01"); 

这只会引发异常:

org.apache.commons.imaging.ImageWriteException:标记期望20个字节,而不是1个字节

到目前为止,我唯一能够成功写入的唯一标签是 ExifTagConstants.EXIF_TAG_USER_COMMENT .

如何使用/编写这些标签(作者/艺术家,日期,海拔高度...)?

我设法找到了两个标签:

  exifDir.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR,测试作者");//作者exifDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE,新的RationalNumber(3,1));//海拔 

...但是它们未写入文件中.

  exifDir.add(ExifTagConstants.EXIF_TAG_USER_COMMENT,我的评论"); 

可以工作,所以我知道它实际上是在写标签,但对上面的两个都不起作用.知道有什么问题吗?

正如@haraldK所述:GPS数据不是实际EFIX目录的一部分,"Apache Commons Imaging"库中也是如此./p>

所以不要用来写高度

  double someDouble = 123.123456789;int alt =(int)Math.round(someDouble * 1000);//四舍五入到小数点后三位最后的TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();exifDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE);exifDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE,新的RationalNumber(alt,1000)); 

使用:

  final TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory();gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE);gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE,新的RationalNumber(alt,1000)); 

这会将"123.123"写入可通过Windows资源管理器查看的海拔高度"字段(右键单击图像-> 属性-> 详细信息)

其他标签:

  final TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();最后的TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory();最后的TiffOutputDirectory rootDir = outputSet.getOrCreateRootDirectory();最后的TiffOutputDirectory intDir = outputSet.getInteroperabilityDirectory();//不知道这是做什么用的//写入作者"字段rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR);rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR,我");//写入程序名称"字段rootDir.removeField(ExifTagConstants.EXIF_TAG_SOFTWARE);rootDir.add(ExifTagConstants.EXIF_TAG_SOFTWARE,我的应用");//写入日期"字段exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,"1970:01:01 12:34:56");//写入数字化日期"exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED);exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED,"1970:01:01 12:34:56");//在属性"中不可见(使用图像编辑软件查看)//编写GPS时间戳gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP);gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP,"1970:01:01");//显然只写年&在属性"中不可见(使用图像编辑软件查看) 

我还没有为获取日期"找到正确的标签,因此,如果有人知道确切的标签,请对此答案发表评论.

I'm using the Apache Commons Imaging library (Java 8, you can find my code here) and I've come across a few problems with tags:

If I open the image info of e.g. this .jpg file with Win 10, there are "Origin" tags, e.g. "Authors" and "Date acquired":

You can find a list of EXIF tags here and it includes the "Authors" one and also an additional "Artist" one. The "Artist" tag seemed to have existed in the library at one point (source) but the apidocs don't list it anymore and ExifTagConstants.TIFF_TAG_ARTIST doesn't exist. Same thing with the "GPSAltitude" tag: It should exist according to the EXIF list but I can't seem to find it in the library.

I tried to use the "Maker" tag instead:

final TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();
exifDir.removeField(ExifTagConstants.EXIF_TAG_MAKER_NOTE);
exifDir.add(ExifTagConstants.EXIF_TAG_MAKER_NOTE, "Test Maker");

But ExifTagConstants.EXIF_TAG_MAKER_NOTE's type of TagInfoUndefineds doesn't seem to be valid for exifDir.add.

I also tried to add the date:

exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED);
exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED, "1970/01/01");

This just throws an exception:

org.apache.commons.imaging.ImageWriteException: Tag expects 20 byte(s), not 1

The only tag I've managed to successfully write so far is ExifTagConstants.EXIF_TAG_USER_COMMENT.

How do I use/write these tags (author/artist, date, altitude,...)?

Edit:

I managed to find two of the tags:

exifDir.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, "Test Author");//Author
exifDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, new RationalNumber(3, 1));//Altitude

... but they aren't written into the file.

exifDir.add(ExifTagConstants.EXIF_TAG_USER_COMMENT, "my comment");

works, so I know it's actually writing tags, it just doesn't work for the two above. Any idea what's wrong?

解决方案

As @haraldK already mentioned: GPS data isn't part of the actual EFIX directory, which is also the case in the "Apache Commons Imaging" library.

So instead of writing the altitude with

double someDouble = 123.123456789;
int alt = (int) Math.round(someDouble*1000); //round to 3 decimal places
final TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();
exifDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE);
exifDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, new RationalNumber(alt, 1000));

use:

final TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory();
gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE);
gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, new RationalNumber(alt, 1000));

This will write "123.123" into the "Altitude" field that can be viewed through the Windows Explorer (right-click on image -> Properties -> Details).

As for the other tags:

final TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();
final TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory();
final TiffOutputDirectory rootDir = outputSet.getOrCreateRootDirectory();
final TiffOutputDirectory intDir = outputSet.getInteroperabilityDirectory(); //Not sure what this one is used for

//Writing into the "Authors" field
rootDir.removeField(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR);
rootDir.add(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, "Me");

//Writing into the "Program Name" field
rootDir.removeField(ExifTagConstants.EXIF_TAG_SOFTWARE);
rootDir.add(ExifTagConstants.EXIF_TAG_SOFTWARE, "My App");

//Writing into the "Date taken" field
exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, "1970:01:01 12:34:56");

//Writing into the "Digitized Date"
exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED);
exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED, "1970:01:01 12:34:56");
//Not visible in "Properties" (use image editing software to see it)

//Writing the GPS time stamp
gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP);
gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, "1970:01:01");
//Apparently only writes year & not visible in "Properties" (use image editing software to see it)

I haven't found the right tag for "Date Acquired" yet, so if someone knows the exact one, please comment on this answer.

这篇关于Apache Commons Imaging(EXIF):缺少标签/标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆