How to get the dpi of an image(Java)

2020-03-03 07:34发布

In c#, we can use Image.HorizontalResolution and Image.VerticalResolution.

But in java, how to get it?

I found ImageInfo.java, but it only support a few image types.

http://kickjava.com/src/imageinfo/ImageInfo.java.htm

标签: java image dpi
7条回答
Evening l夕情丶
2楼-- · 2020-03-03 08:06

It is working for me.

 try {

        final ImageInfo imageInfo = Sanselan.getImageInfo(new File("C:/Users/AngryMan/Desktop/abc.png"));
        final int physicalWidthDpi = imageInfo.getPhysicalWidthDpi();
        final int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
        System.out.println("physicalWidthDpi :"+physicalWidthDpi );
        System.out.println("physicalHeightDpi : "+physicalHeightDpi);

    } catch (Exception e) {
        e.printStackTrace();
    }

Maven Depndency

 <!-- https://mvnrepository.com/artifact/org.apache.sanselan/sanselan -->
    <dependency>
        <groupId>org.apache.sanselan</groupId>
        <artifactId>sanselan</artifactId>
        <version>0.97-incubator</version>
    </dependency>
查看更多
登录 后发表回答