问题描述
我正在尝试从PNG图像格式中提取元数据。我正在使用这个库吗?
I'm trying to extract metadata from a PNG image format. I'm using this library? http://code.google.com/p/metadata-extractor/
即使声称支持PNG格式,我也会收到错误不支持文件格式
当我尝试使用PNG图片。从源代码(在方法 readMetadata
中,它看起来似乎不支持PNG格式:
Even though it claims that PNG format is supported I get an error File format is not supported
when I try it with a PNG image. From the source (in method readMetadata
also it looks like that it doesn't support PNG format: http://code.google.com/p/metadata-extractor/source/browse/Source/com/drew/imaging/ImageMetadataReader.java?r=1aae00f3fe64388cd14401b2593b580677980884
我也尝试过这段代码,但它也是不会在PNG上提取元数据。
I've also given this piece of code a try as well but it also doesn't extract the metadata on the PNG.
BTW,我正在使用imagemagick在PNG上添加元数据:
BTW, I'm adding metadata on PNG with imagemagick like this:
mogrify -comment "Test" Demo/myimage.png
有没有人将此库用于PNG格式,还是有其他方式从PNG图像中提取元数据?
Has anyone used this library for PNG format or are there other ways to extract metadata from PNG image?
推荐答案
你可以尝试(我是开发商)
You can try PNGJ (I'm the developer)
参见此处转储所有块。
如果你想阅读一个特定的文本块(回想一下,在PNG中,每个文本元数据都有一个键和一个值),你可以写一下
See eg here an example to dump all chunks.If you want to read a particular text chunk (recall that in PNG each textual metadata has a key and a value), you could write
pngr.getMetadata().getTxtForKey("mykey")
一个有用的小用于查看PNG块结构的Windows程序是
A useful little Windows program to peek inside PNG chunk structure is TweakPNG
更新:如果你想检查所有文本块(请记住有三种类型有一些差异,但是......)
Update: If you want to check all textual chunks (bear in mind that there are three types with some differences, but...)
PngReader pngr = FileHelper.createPngReader(new File(file));
pngr.readSkippingAllRows();
for (PngChunk c : pngr.getChunksList().getChunks()) {
if (!ChunkHelper.isText(c)) continue;
PngChunkTextVar ct = (PngChunkTextVar) c;
String key = ct.getKey();
String val = ct.getVal();
// ...
}
还要注意文本块允许重复按键。
Bear also in mind that textual chunks with repeated keys are allowed.
这篇关于从PNG图像中提取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!