Java如何获取图片Dpi

使用Apache Commons Imaging 图像处理库
引入依赖

// https://mvnrepository.com/artifact/org.apache.commons/commons-imaging
compile group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-alpha1'

编写测试方法

public static void main(String[] args) throws Exception {
        ImageInfo imageInfo = Imaging.getImageInfo(new File("C:\\Users\\Administrator\\Desktop\\图片素材\\2.jpg"));
        System.out.println("dpi为"+imageInfo.getPhysicalHeightDpi());
}

方法执行成功打印Dpi

你可能感兴趣的:(Java如何获取图片Dpi)