繁体   English   中英

java元数据提取器标签说明

[英]java metadata-extractor tag description

我正在使用Java库Metadata-extractor,尽管使用了tag.getDescription可以正常工作,但是无法使用下面的getUserCommentDescription方法代码正确提取标签描述:

String exif = "File: " + file;
File jpgFile = new File(file);
Metadata metadata = ImageMetadataReader.readMetadata(jpgFile);

for (Directory directory : metadata.getDirectories()) {
    String directoryName = directory.getName();
    for (Tag tag : directory.getTags()) {
       String tagName = tag.getTagName();
       String description = tag.getDescription();
       if (tagName.toLowerCase().contains("comment")) {
          Log.d("DEBUG", description);
       }
       exif += "\n " + tagName + ": " + description;  //Returns the    correct values.
       Log.d("DEBUG", directoryName + " " + tagName + " " + description);
   }
   if (directoryName.equals("Exif IFD0")) {
      // create a descriptor
      ExifSubIFDDirectory exifDirectory =   metadata.getDirectory(ExifSubIFDDirectory.class);
      ExifSubIFDDescriptor descriptor = new     ExifSubIFDDescriptor(exifDirectory);
      Log.d("DEBUG","Comments: " +    descriptor.getUserCommentDescription()); //Always null.
  }

我在这里想念什么吗?

您正在检查目录名称Exif IFD0 ,然后访问ExifSubIFDDirectory

在循环外尝试以下代码:

Metadata metadata = ImageMetadataReader.readMetadata(jpgFile);
ExifSubIFDDirectory exifDirectory = metadata.getDirectory(ExifSubIFDDirectory.class);
ExifSubIFDDescriptor descriptor = new ExifSubIFDDescriptor(exifDirectory);
String comment = descriptor.getUserCommentDescription();

如果返回null则可能是编码问题或错误 如果运行此代码:

byte[] commentBytes =
    exifDirectory.getByteArray(ExifSubIFDDirectory.TAG_USER_COMMENT);

数组中是否有字节?

如果是这样,请在问题跟踪器中打开一个问题,并提供可用于重现该问题的示例图像。 您必须授权您提供的任何图像可在公共领域中使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM