I'm trying to automate image processing using Drew Noates' metadata extractor (https://drewnoakes.com/code/exif/). According to his documentation, it can handle Canon's RAW file format. However, I have yet to find a way to extract information like the creation date.

I wrote a small utility to dump all directories & tags returned by the library. Here are the relevant portions of that utility:

private static PrintStream OUT = System.out;

private static void processFile(final File f)
{
    final String lcName = f.getName().toLowerCase();

    try
    {
        final Metadata metadata = ImageMetadataReader.readMetadata(f);

        dumpDirectories(metadata);
    }
    catch (final ImageProcessingException e)
    {
        System.err.println("Error while processing \"" + f.getAbsolutePath() + "\" : " +
            e.getMessage());
    }
    catch (final IOException e)
    {
        System.err.print("Error while processing \"" + f.getAbsolutePath() + "\" : ");
        e.printStackTrace();
    }
}

private static void dumpDirectories(final Metadata metadata)
{
    for (final Directory directory : metadata.getDirectories())
    {
        OUT.print('\t');
        OUT.println(directory.getClass().getName());

        for (final Tag tag : directory.getTags())
        {
            final Object value = directory.getObject(tag.getTagType());

            OUT.print("\t\t");
            OUT.print(tag.getTagName());
            OUT.print(" = ");

            if (value != null && value.getClass().isArray())
            {
                if (value instanceof byte[])
                {
                    OUT.println(Arrays.toString((byte[])value));
                }
                else if (value instanceof float[])
                {
                    OUT.println(Arrays.toString((float[])value));
                }
                else if (value instanceof int[])
                {
                    OUT.println(Arrays.toString((int[])value));
                }
                else if (value instanceof short[])
                {
                    OUT.println(Arrays.toString((short[])value));
                }
                else
                {
                    OUT.println(Arrays.deepToString((Object[]) value));
                }
            }
            else
            {
                OUT.println(value);
            }
        }
    }
}

If I run the above code against my .crw file, I get the following output:

com.drew.metadata.file.FileTypeDirectory
    Detected File Type Name = CRW
    Detected File Type Long Name = Canon Camera Raw
    Expected File Name Extension = crw
com.drew.metadata.file.FileSystemDirectory
    File Name = blah.crw
    File Size = 3040264
    File Modified Date = Sat Jun 28 15:28:51 EDT 2003

However, nowhere do I see the actual date that the picture was taken ("File Modified Date" is coming from the file system, so it may or may not match the date when the picture was taken). I believe that there is a small thumbnail JPEG embedded in the CRW that has all the proper EXIF information. I used to invoke a batch file that I wrote to:
a) extract that thumbnail JPEG
b) then extract the date from that thumbnail JPEG

So as an alternate solution, I was hoping to use metadata-extractor to get a hold of that thumbnail JPEG, then use metadata-extractor to get the date from that thumbnail JPEG. However, as you can see from the output above, the thumbnail JPEG is not made accessible by metadata-extractor either.

So far, I have not found a way or documentation or code sample explaining how to do this.

1 Answers

0
jens freudenau On

Like the docs ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);

Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);