Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the dpi of an image(Java)

Tags:

java

image

dpi

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

like image 586
guhai Avatar asked Aug 22 '11 02:08

guhai


1 Answers

You can use Apache Commons Sanselan library to get image info: http://commons.apache.org/imaging/index.html.

final ImageInfo imageInfo = Sanselan.getImageInfo(file_);

final int physicalWidthDpi = imageInfo.getPhysicalWidthDpi();
final int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
like image 134
br2000 Avatar answered Nov 03 '22 00:11

br2000