1

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.
  }

ここで何か不足していますか?

4

1 に答える 1

0

ディレクトリ名を確認してからExif IFD0ExifSubIFDDirectory.

ループの外で次のコードを試してください。

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);

配列にバイトがありますか?

その場合は、 Issue Trackerで問題を開き、問題の再現に使用できるサンプル画像を含めてください。提供する画像は、パブリック ドメインで使用することを承認する必要があります。

于 2015-01-28T09:03:50.187 に答える