2

I have a single tiff file with multiple images inside. I want to extract the Image Description value for each of the images. I'm not sure why, but when I use ImageMetaDataReader, it's only returning the first and last Image Description. I have verified the data is there using exiftool and dumping to a xml tree. Any suggestions why this isn't working?

Metadata metadata = ImageMetadataReader.readMetadata(createInputFile());
            for (Directory directory : metadata.getDirectories())
            {
                for (Tag tag : directory.getTags())
                {
                        fileWriter.write(String.format(tag + "%n"));
                }
            }

All tags using metadata-extractor

[Exif IFD0] New Subfile Type - Full-resolution image
[Exif IFD0] Image Width - 1254 pixels
[Exif IFD0] Image Height - 558 pixels
[Exif IFD0] Bits Per Sample - 1 bits/component/pixel
[Exif IFD0] Compression - T6/Group 4 Fax
[Exif IFD0] Photometric Interpretation - WhiteIsZero
[Exif IFD0] Fill Order - Normal
[Exif IFD0] Image Description - 12345                         
[Exif IFD0] Strip Offsets - 399
[Exif IFD0] Orientation - Top, left side (Horizontal / normal)
[Exif IFD0] Samples Per Pixel - 1 samples/pixel
[Exif IFD0] Rows Per Strip - 558 rows/strip
[Exif IFD0] Strip Byte Counts - 7899 bytes
[Exif IFD0] Minimum Sample Value - 0
[Exif IFD0] Maximum Sample Value - 1
[Exif IFD0] X Resolution - 200 dots per inch
[Exif IFD0] Y Resolution - 200 dots per inch
[Exif IFD0] Planar Configuration - Chunky (contiguous for each subsampling pixel)
[Exif IFD0] Unknown tag (0x0125) - 0
[Exif IFD0] Resolution Unit - Inch
[Exif Thumbnail] New Subfile Type - Full-resolution image
[Exif Thumbnail] Image Width - 1253 pixels
[Exif Thumbnail] Image Height - 558 pixels
[Exif Thumbnail] Bits Per Sample - 1 bits/component/pixel
[Exif Thumbnail] Compression - T6/Group 4 Fax
[Exif Thumbnail] Photometric Interpretation - WhiteIsZero
[Exif Thumbnail] Fill Order - Normal
[Exif Thumbnail] Image Description - 12345                         
[Exif Thumbnail] Strip Offsets - 38596
[Exif Thumbnail] Orientation - Top, left side (Horizontal / normal)
[Exif Thumbnail] Samples Per Pixel - 1 samples/pixel
[Exif Thumbnail] Rows Per Strip - 558 rows/strip
[Exif Thumbnail] Strip Byte Counts - 1288 bytes
[Exif Thumbnail] Minimum Sample Value - 0
[Exif Thumbnail] Maximum Sample Value - 1
[Exif Thumbnail] X Resolution - 200 dots per inch
[Exif Thumbnail] Y Resolution - 200 dots per inch
[Exif Thumbnail] Planar Configuration - Chunky (contiguous for each subsampling pixel)
[Exif Thumbnail] Unknown tag (0x0125) - 0
[Exif Thumbnail] Resolution Unit - Inch
[File Type] Detected File Type Name - ARW
[File Type] Detected File Type Long Name - Sony Camera Raw
[File Type] Expected File Name Extension - arw
[File] File Name - test_images.tif
[File] File Size - 39884 bytes
[File] File Modified Date - Wed Apr 10 08:51:24 -02:30 2019


All tags using Exiftool.

ExifTool Version Number         : 11.44
File Name                       : test_images.tif
Directory                       : .
File Size                       : 39 kB
File Modification Date/Time     : 2019:04:10 08:51:24-02:30
File Access Date/Time           : 2019:06:17 16:04:44-02:30
File Inode Change Date/Time     : 2019:06:17 15:16:47-02:30
File Permissions                : rwxr-xr-x
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Subfile Type                    : Full-resolution Image
Image Width                     : 1254
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 399
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 7899
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1253
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 8689
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 1288
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1254
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 10368
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 7899
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1253
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 18658
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 1288
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1254
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 20337
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 7899
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1253
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 28627
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 1288
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1254
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 30306
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 7899
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Subfile Type                    : Full-resolution Image
Image Width                     : 1253
Image Height                    : 558
Bits Per Sample                 : 1
Compression                     : T6/Group 4 Fax
Photometric Interpretation      : WhiteIsZero
Fill Order                      : Normal
Image Description               : 12345
Strip Offsets                   : 38596
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 1
Rows Per Strip                  : 558
Strip Byte Counts               : 1288
Min Sample Value                : 0
Max Sample Value                : 1
X Resolution                    : 200
Y Resolution                    : 200
Planar Configuration            : Chunky
T6 Options                      : (none)
Resolution Unit                 : inches
Image Size                      : 1254x558
Megapixels                      : 0.700
J_D
  • 740
  • 8
  • 17

1 Answers1

1

If you want to retrieve metaData from the image in the Android project. Then you can do that with the help of https://github.com/drewnoakes/metadata-extractor implement this in your Gradle using implementation 'com.drewnoakes:metadata-extractor:2.12.0'

Complete code is as follows

private static String getImageMetaData(Uri image1) {

    try {
        InputStream inputStream = FILE_CONTEXT.getContentResolver().openInputStream(image1);
        try {
            image1.getEncodedUserInfo();
            Metadata metadata = ImageMetadataReader.readMetadata(inputStream);
            for (Directory directory1 : metadata.getDirectories()) {
                if (directory1.getName().equals("Exif IFD0")) {
                    for (Tag tag : directory1.getTags()) {
                        if (tag.getTagName().equals("Date/Time")) {
                            return tag.getDescription();
                        }
                    }
                }
            }
        } catch (ImageProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
DavidW
  • 29,336
  • 6
  • 55
  • 86
Sahil Bansal
  • 609
  • 8
  • 6
  • Please don't post the same code in multiple places https://stackoverflow.com/questions/50114454/metadata-extractor-class-file-unable-to-import-in-java-class/58508067#58508067 https://stackoverflow.com/questions/56103231/getting-filenotfoundexception-permission-denied-when-trying-to-read-metadata-f - instead flag the question as a duplicate if appropriate – DavidW Oct 22 '19 at 16:54
  • Also https://stackoverflow.com/questions/12623302/get-meta-data-of-image-android/58507971#58507971 – DavidW Oct 22 '19 at 16:55