Apache Commons Imaging (EXIF):设置标签/标签丢失 [英] Apache Commons Imaging (EXIF): Setting tags/tags missing

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

问题描述

我正在使用 Apache Commons Imaging

您可以在此处找到一份 EXIF 标签列表 它包括一个作者"和一个额外的艺术家".艺术家"标签似乎曾经存在于图书馆中(source) 但apidocs 不再列出它并且 ExifTagConstants.TIFF_TAG_ARTIST 不存在.与GPSAltitude"标签相同的事情:它应该根据 EXIF 列表存在,但我似乎无法在库中找到它.

我尝试使用Maker"标签:

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

但是 ExifTagConstants.EXIF_TAG_MAKER_NOTETagInfoUndefineds 类型似乎对 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, new RationalNumber(3, 1));//海拔高度

...但它们没有写入文件.

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

有效,所以我知道它实际上是在写标签,只是对上面两个不起作用.知道出了什么问题吗?

解决方案

正如@haraldK 已经提到的:GPS 数据不是实际 EFIX 目录的一部分,在Apache Commons Imaging"库中也是如此.

所以不要用

写海拔高度

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, new RationalNumber(alt, 1000));

使用:

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

这会将123.123"写入可通过 Windows 资源管理器查看的高度"字段中(右键单击图像 -> Properties -> Details).

至于其他标签:

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");//显然只写year &在属性"中不可见(使用图像编辑软件查看)

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

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天全站免登陆