OK, I agree this is a strange question, but bear with me.
I have a TIFF image and I am using Windows. When I right-click and go to Properties, I see Width = 1728 pixels and Height = 1146 pixels. When I read it with Java as a BufferedImage and call getWidth() and getHeight(), I see the same things. When I open it with MS Paint, I see the same size.
But the problem is that this size is not correct because the height is too small and the image looks idiotic. Now the interesting part: when I open it with IrfanView, I see it OK, with Height = 2292 pixels. When I open it with Windows Photo Viewer, it looks OK with Height = 2292 pixels.
So my question is: How did IrfanView and Windows Photo Viewer manage to recognize the correct height, although it was specified wrong in the metadata of the image? And how to do the same in Java? I don’t want to show an idiotic image to the user.
P.S The image comes from outside and I can’t do anything about the wrong metadata…
I resolved the problem. In fact the image was inappropriate from the beginning. The reason why
IrfanViewshows it OK, is that it compares theHorizontalandVerticalDPIand if they are not equal, it resizes the image to make them equal.For example:
When IrfanView opens the image it makes the following:
Height = Height * (HorizontalDPI / VerticalDPI) = 600 * 2 = 1200.I ended up doing the same in my software. Everything is working fine:)
I hope this post will be useful to other people:)