This discussion is archived
4 Replies Latest reply: Oct 30, 2011 3:27 PM by 896874 RSS

read metadata of jpeg

567684 Newbie
Currently Being Moderated
hi guys:
I have a problem about using ImageReader.reader.getImageMetadata to fetch metadata from a jpeg file . Unfortunately, i got such error
Exception in thread "main" javax.imageio.IIOException: ICC APP2 encountered without prior JFIF!
It seems like a bug of java . How could I resolve it?

Besides that, I have another question. Could we get one or two specific metadata from a jpeg file without load whole file into the memory. For example, I only want the location information in a photo which are took by my iphone.

Please help me . I'm not a image handling expert.
Thanks.
  • 1. Re: read metadata of jpeg
    Maxideon Explorer
    Currently Being Moderated
    You'll need to post a link to the jpeg in question.
    Besides that, I have another question. Could we get one or two specific metadata from a jpeg file without load whole file into the memory. For example, I only want the location information in a photo which are took by my iphone.
    You have to load all of the metadata. This isn't the whole file, only the first few KB or so of it.
  • 2. Re: read metadata of jpeg
    567684 Newbie
    Currently Being Moderated
    Ok [test photo|http://www.panoramio.com/photo/44952561]
    the link is the photo .
    It will cause exception when i read the meatadata.
    Still,I'm not sure about how to load metadata without loading the whole file.
  • 3. Re: read metadata of jpeg
    803691 Newbie
    Currently Being Moderated
    Irfan View's EXIF viewer does not show any EXIF metadata from that image.
  • 4. Re: read metadata of jpeg
    896874 Newbie
    Currently Being Moderated
    Some points should help.
    1. There are two types of meta data available from after reading, or before writing with an image.
    a. stream meta data
    b. Image meta data

    2. you need to read the image completely first with the java.imageio.ImageReader of which you can choose to read only image-index number "0" (that is the main image) . ( and generally there are no extra index of images - "no thumbnails").

    3. You can obtain the Image meta data better from the returned IIOImage object, but finally you will need to be good at making iteration loops to use the getTree() method to obtain the XML "org.w3c.dom.Node" that contais the meta data, that has been formatted by the java API.

    4. About the "JFIF" name in .jpeg and .jpg streams , it does not like that "format name" on the stream and throws an error , i haven't used the newer JAI classes at this time that use Tiff format and JPEG 2000 format.
    Only .tiff .jpeg .jpg extensions in java can have EXIF data , "stream data is independent of" EXIF and GPS info, and is with the image type/format spec.
    note .jfif is an extension sometimes found on jpeg and jpg types and heavily realted compressor specs that carry non stream meta data.

    Edited by: 893871 on 30/10/2011 11:34

    Edited by: EJP on 31/10/2011 09:25: thanks for your answer although you're a year late. Removed your question which should be asked in a new thread. Nobody will see it here and in any case reviving old threads with new questions is considered bad form. Locking this thread.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points