3

I'm trying to read the meta-data of a PNG file with java following the solution proposed here.

But the method ImageIO.getImageReaders(inputStream) is returning an empty list of readers. I assured that the stream is correct by reading it via ImageIO.read and rendering the resulting Image to the screen.

And this is why I'm confused: since ImageIO.read returns a valid image, i assume there is some ImageReader claiming to be able to interpret this stream. Is there a difference between interpreting image data and the meta-data of the image?

Any hints or even solutions to this problem?

Thank you very much.

Community
  • 1
  • 1
Sebastian Schmitt
  • 433
  • 1
  • 5
  • 18
  • inputStream is a InputStream or a ImageInputStream? And by "metadata " you mean things like width and height? – leonbloy Apr 17 '13 at 18:08
  • `inputStream` is an `InputStream` (obtained by [`java.lang.ClassLoader.getResourceAsStream`](http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String))). And by "metadata" I mean exactly those two properties (height & width). – Sebastian Schmitt Apr 17 '13 at 20:29

1 Answers1

5

I believe that ImageIO.getImageReaders() expects an ImageInputStream, you can try to create one from your InputStream using createImageInputStream. I guess that's what ImageIO.read(InputStream) does under the hood.

Anyway, if you already know that you have a PNG, why not use getImageReadersByFormatName("png") ?

BTW: height and width (and color model, etc) can be considered as "image metadata", in the sense that they are not part of the pixels values (which would be the real data), but in common parlance, they are regarded rather as image (esential) properties. The image metadata is generally (and specifcally in IIOMetadata) understood to be additional "miscelanous" data (as physical resolution, timestamp) which is normally not needed to access the image data.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • This does not work for me. `getImageReadersByFormatName("png")` is not suitable here due to my actual target application. The code has to be able to read the metadata of images that are encoded in different (i.e. not only png) formats. – Sebastian Schmitt Apr 18 '13 at 06:06
  • 1
    Silly me: I failed to update my code correctly. I was getting a reader by the help of the ImageInputStream but used my old plain InputStream as the reader's input. Now that I fixed that, it works fine! Thank you very much!! – Sebastian Schmitt Apr 18 '13 at 06:24