在Java中读取jpeg文件的量化表 [英] Reading quantization tables of jpeg files in Java

查看:475
本文介绍了在Java中读取jpeg文件的量化表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索一个Java库,它有一个用于返回图像DQT的接口。我知道,例如exiftool可以做到,但Java包装器似乎没有接口。任何指针都表示赞赏。一些JNI绑定也可能适用于我。

I'm searching for a Java library that has an interface for returning DQT of an image. I know that e.g. exiftool can do it, but the Java wrapper does not seem to have an interface for that. Any pointers are appreciated. Some JNI bindings will probably work for me as well.

提前致谢!

推荐答案

您可以使用ImageIO的 JPEGImageReader IIOMetadata 获取DQT。

You can get the DQTs from the IIOMetadata using ImageIO's JPEGImageReader.

IIOMetadata metadata = jpegReader.getImageMetadata();

IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(metadata.getNativeMetadataFormatName());
NodeList dqt = root.getElementsByTagName("dqt");
NodeList dqtables = ((IIOMetadataNode) dqt.item(0)).getElementsByTagName("dqtable");
JPEGQTable[] qTables = new JPEGQTable[dqtables.getLength()];

for (int i = 0; i < dqtables.getLength(); i++) {
    qTables[i] = (JPEGQTable) ((IIOMetadataNode) dqtables.item(i)).getUserObject();
    System.out.println("qTables: " + qTables[i]);
}

参见图像元数据DTD ,用于提供有关可用数据以及如何访问数据的文档。

See Image Metadata DTD for docs on what data is available and how to access it.

我总是发现 IIOMetadata akward并且不方便,但是它完成了工作(除了一些非spec JPEG文件)。

I've always found the IIOMetadataakward and inconvenient, but it does the job (except for some non-spec JPEG files).

如果您不喜欢API,那么自己解析JFIF流和DQT段并不困难。灵感来自旧博文和一些C示例代码,我写了 JPEGQuality ,它解析DQT并尝试重新估计JPEG的质量设置。

If you don't like the API, it's not too hard to parse the JFIF stream and the DQT segments yourself. Inspired by an old blog post and some C sample code, I wrote JPEGQuality, that parses the DQT and also tries to re-estimate the quality setting of the JPEG.

这篇关于在Java中读取jpeg文件的量化表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆