Question

So I'm looking here at EXIF documentation. (http://www.media.mit.edu/pia/Research/deepview/exif.html)
I need to do this manually, so I'm trying to store all the EXIF data into a byte array, which I can use later. The end marker for EXIF data is FFD9 according to the link. Would it be fine to just go about reading EXIF data up until FFD9 is encountered, and save all the EXIF data away for later use? Or is that a problem, that FFD9 could possibly occur somewhere else in the mass chunk of metadata information, while traversing it?

Was it helpful?

Solution

FFD8 and FFD9 is the start and end of a JPEG image (or an EXIF thumbnail), not an EXIF chunk. EXIF data in JPEGs is stored inside a chunk marked by the FFE1 maker, there is no end marker. You have to read the next 2 bytes to get the EXIF data length and read as much.

For example, ffe1 1b61 4578 6966, where 1b61 is the amount of bytes in the EXIF data chunk. 7009 bytes, once you've read these you can stop. This is the only correct way.

Some hints may be available to you to check whether you're on the correct path or not (no off by 1 errors in reading etc.). Since EXIF thumbnails are JPEGs they will end with FFD9 as well, and a thumbnail entry will very probably be the last entry inside the EXIF chunk. So the EXIF chunk will very probably end with a FFD9. A new FFEx marker will follow, this is the start of a completely different chunk.

Again: do not search for FFD9 and stop, though, since the EXIF chunk may contain several thumbnails which end in FFD9, get the header size and read accordingly.

This is for JPEG. In other image formats EXIF will be stored differently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top