views:

225

answers:

4

Greetings,

I'm going to get exif info from some images using android. I know there are some standard java lib's out there that I could use with the device. I'm sure I will end up using one.

But in the meantime can someone explain to me how this information is encoded inside a JPG? Where / how would you usually get the info from the document. When I opent he document up with a text editor its all binary.

Curious as to how it works and how I could potentially read the data in question.

+3  A: 

Wikipedia has a few pointers on how and where exactly EXIF data is stored in a file. Of course, there's always the standard itself to read up.

Joey
+1  A: 

If you search for the string "Exif" you will find the start of the Exif data -- it's quite complicated, and I would recommend using a library -- (e.g. my company's DotImage if you were using .NET).

Here's a high level description though:

The Exif itself is inside of an AppMarker -- the three bytes before will be E1 (AppMarker 1) and the size of the marker's data in the endianness of the file. Two bytes after the Exif you will see the endianness marker (e.g. 49 49 means II which means Intel, little endian -- that means that 2 bytes numbers have the low byte first in the file).

The rest of the data uses offsets extensively, the offset is from the location of the first endian byte (the 49 in the above case)

8 bytes from this offset is a 2-byte number which is the number of exif tags. If you are in II byte order, reverse the bytes to read the length.

Then there will be this number of 12 byte records. Each one is:

2 bytes: Tag ID
2 bytes: Tag Type
4 bytes: Length
4 bytes: data if the data is 4 bytes or less, or an offset to the data

After the N 12 byte records, you will have the data pointed to by each offset used in the above N records. You need to look up ids and types to see what they mean and how they are represented.

Lou Franco
A: 

It's pretty tedious to parse EXIF data but you can find many libraries to parse it. My favorite one for Java is,

http://www.java2s.com/Open-Source/Java-Document/Web-Server/Jigsaw/org/w3c/tools/jpeg/Exif.java.htm

ZZ Coder
A: 

This is one of the good libraries for Java and EXIF: http://www.drewnoakes.com/code/exif/

Daniil
Thanks for teh link. I've come across a number of libraries. Was curious as to how it works :-)
steve