问题描述
我使用 javax.imageio
库成功读取了 .png、.jpeg、.tif 和 .jpf 图像的 DPI(实际上是 PPI)。我会解析 javax_imageio_1.0
元数据并使用以下代码查找 VerticalPixelSize 和 HorizontalPixelSize 值:
public static int getimageVerticalDensity(String imagePath) throws IOException {
IIOMetadatanode root = initReader(imagePath);
if (root != null) {
NodeList nodes = root.getElementsByTagName("VerticalPixelSize");
if (nodes.getLength() > 0) {
IIOMetadatanode dpcWidth = (IIOMetadatanode) nodes.item(0);
NamednodeMap nnm = dpcWidth.getAttributes();
Node item = nnm.item(0);
int xDPI = Math.round(25.4f / Float.parseFloat(item.getNodeValue()));
return xDPI;
}
}
return 0;
}
private static IIOMetadatanode initReader(String imagePath) throws IOException {
ImageInputStream iis = ImageIO.createImageInputStream(new File(imagePath));
Iterator it = ImageIO.getimageReaders(iis);
if (!it.hasNext()) {
return null;
}
ImageReader reader = (ImageReader) it.next();
reader.setInput(iis);
IIOMetadata Meta = reader.getimageMetadata(0);
IIOMetadatanode root = (IIOMetadatanode) Meta.getAsTree("javax_imageio_1.0");
return root;
}
似乎在 javadoc 中定义的 GIF 元数据中没有 VerticalPixelSize 和 HorizontalPixelSize 标签。由于我在阅读元数据方面没有经验,有没有办法根据 .gif 元数据中的可用值计算每英寸/毫米/任何内容的像素?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)