元数据提取器中的getThumbnailData()为CR2文件返回null

时间:2016-04-21 00:22:23

标签: java exif metadata-extractor

我正在使用metadata-extractor的java版本2.8.1来读取CR2文件。根据标签转储,有一个Exif Thumbnail目录,它声称有一个缩略图偏移量和长度。但是,当我在getThumbnailData()对象上调用ExifThumbnailDirectory时,它返回null。知道为什么吗?照片是用佳能EOS 70D相机拍摄的。当我用JPEG调用它时,代码工作正常。可以找到源照片文件here

[Exif Thumbnail] - Thumbnail Offset(0x0201) = 80600 bytes
[Exif Thumbnail] - Thumbnail Length(0x0202) = 15272 bytes
[Exif Thumbnail] - Image Width(0x0100) = 5568 pixels
[Exif Thumbnail] - Image Height(0x0101) = 3708 pixels
[Exif Thumbnail] - Bits Per Sample(0x0102) = 16 16 16 bits/component/pixel
[Exif Thumbnail] - Thumbnail Compression(0x0103) = JPEG (old-style)
[Exif Thumbnail] - Photometric Interpretation(0x0106) = RGB
[Exif Thumbnail] - Strip Offsets(0x0111) = 4472188
[Exif Thumbnail] - Samples Per Pixel(0x0115) = 3 samples/pixel
[Exif Thumbnail] - Rows Per Strip(0x0116) = 309 rows/strip
[Exif Thumbnail] - Strip Byte Counts(0x0117) = 22883515 bytes
[Exif Thumbnail] - Planar Configuration(0x011c) = Chunky (contiguous for each subsampling pixel)
[Exif Thumbnail] - Unknown tag (0xc5d9) = 2
[Exif Thumbnail] - Unknown tag (0xc6c5) = 1
[Exif Thumbnail] - Unknown tag (0xc6dc) = 450 301 7 4
[Exif Thumbnail] - Unknown tag (0xc5d8) = 1
[Exif Thumbnail] - Unknown tag (0xc5e0) = 1
[Exif Thumbnail] - Unknown tag (0xc640) = 1 2784 2784
[File] - File Name(0x0001) = foo.CR2
[File] - File Size(0x0002) = 27361411 bytes

1 个答案:

答案 0 :(得分:2)

应该删除getThumbnailData()方法。当大多数人不使用缩略图时,它会将缩略图的所有数据分配到内存中。在这种情况下,CR2处理器不包含它。

您最好的选择是使用问题中显示的前两个值:

[Exif Thumbnail] - Thumbnail Offset(0x0201) = 80600 bytes
[Exif Thumbnail] - Thumbnail Length(0x0202) = 15272 bytes

使用这些和原始文件,您可以为图像提取byte[]。至少,我99%肯定你可以:)

如果没有,请告诉我,我们可以进一步调查。