从 GIF 图像中读取 DPI 元数据

问题描述

我使用 javax.imageio 库成功读取了 .png、.jpeg、.tif 和 .jpf 图像的 DPI(实际上是 PPI)。我会解析 javax_imageio_1.0 元数据并使用以下代码查找 VerticalPixelSizeHorizo​​ntalPixelSize 值:

  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 元数据中没有 VerticalPixelSizeHorizo​​ntalPixelSize 标签。由于我在阅读元数据方面没有经验,有没有办法根据 .gif 元数据中的可用值计算每英寸/毫米/任何内容的像素?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...