简体   繁体   English

如何从Canon RAW文件(.crw)中提取创建日期等信息

[英]How can I extract info like creation date from a Canon RAW file (.crw)

I'm trying to automate image processing using Drew Noates' metadata extractor ( https://drewnoakes.com/code/exif/ ). 我正在尝试使用Drew Noates的元数据提取器( https://drewnoakes.com/code/exif/ )自动执行图像处理。 According to his documentation, it can handle Canon's RAW file format. 根据他的文档,它可以处理佳能的RAW文件格式。 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: 如果我针对我的.crw文件运行上面的代码,我得到以下输出:

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. 我相信CRW中嵌入了一个小缩略图JPEG,它具有所有正确的EXIF信息。 I used to invoke a batch file that I wrote to: 我曾经调用过我写的批处理文件:
a) extract that thumbnail JPEG a)提取缩略图JPEG
b) then extract the date from that thumbnail JPEG b)然后从该缩略图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. 因此,作为替代解决方案,我希望使用元数据提取器来获取该缩略图JPEG,然后使用元数据提取器从该缩略图JPEG获取日期。 However, as you can see from the output above, the thumbnail JPEG is not made accessible by metadata-extractor either. 但是,正如您从上面的输出中看到的那样,元数据提取器也无法访问缩略图JPEG。

So far, I have not found a way or documentation or code sample explaining how to do this. 到目前为止,我还没有找到解释如何执行此操作的方法或文档或代码示例。

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

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

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

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