Skip to main content

Find out DPI of an image

2 replies [Last post]
Joined: 2009-05-10


I read images with
How can I find out the DPI of the image?

Thank you

P.S. The image is in 90 % of all cases a Tiff with Jpeg compression (old and new).

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-07-10

You should go a different way to read the metadata.
Get your ImageReader instance. Then use the first ImageReader,
set the Input and read IIOImage or only getImageMetadata(pageIndex).
You get the image format neutral metadata xml and parse it for the
desired data.

ImageInputStream iis = ImageIO.createImageInputStream(in);
Iterator it = ImageIO.getImageReaders(iis);
if (!it.hasNext()) {
System.outprintln("No reader for this format");
ImageReader reader = (ImageReader);
IIOMetadata meta = reader.getImageMetadata(0);
IIOMetadataNode dimNode = meta.getStandardDimensionNode();
NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize");
IIOMetadataNode dpcWidth = (IIOMetadataNode)nodes.nextElement();
nodes = dimNode.getElementsByTagName("VerticalPixelSize");
IIOMetadataNode dpcHeight = (IIOMetadataNode)nodes.nextElement();
// ... calc dot per centimeter to dpi : dpi = dpc / 2.54

The whole image neutral metadata format at

Joined: 2009-05-10

Thank you!