How to get the dpi of an image(Java)

后端 未结 7 1887
无人及你
无人及你 2021-01-06 01:51

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

But in java, how to get it?

I found ImageInfo.java, but it only supp

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 01:56

    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

     
        
            org.apache.sanselan
            sanselan
            0.97-incubator
        
    

提交回复
热议问题