I started looking into the possibility of adding geo tags to photos captured from within an iPhone application since Apple’s Camera.app and some third-party apps are doing it.
There is, of course, no standard API to access the EXIF meta data in a JPEG image, so I was using the same iphone-exif library hosted on googlecode as everybody else. Once being passed an UIImage by the iPhone camera through UIImagePickerController and obtaining the JPEG image representation, I was able to add the latitude and longitude values to its EXIF section. All’s well.
The unpleasant surprise came after I saved the geo-tagged image to the iPhone photo album via UIImageWriteToSavedPhotosAlbum(), and pulled it out via iPhoto – the geo tag is gone!
Since pictures taken by the native Camera.app contains proper geo tag info when pulled from iPhoto, I did a second test by getting a photo taken by the native Camera app into code to examine the EXIF data. Of course, I used a UIImagePickerController with source type set to PhotoLibrary and picked the natively captured photo. The JPEG representation of the UIImage passed by the picker controller to the code contains no geo tag either!
So here’s what I think is happening -
1) The UIImage object passed by the UIImagePickerController from either the camera or the photo library is format neutral and thus does not contain EXIF tags which are JPEG meta data, although it would be nice to have the meta data provided to code via some other means if the image source is JPEG.
2) A UIImage object passed through the UIImageJPEGRepresentation() method is a JPEG representation containing only basic EXIF meta data including Orientation, EXIF {ColorSpace, XDimension, YDimension}.
3) When writing out to photo album via UIImageWriteToSavedPhotosAlbum(), all EXIF data are stripped out and replaced with new EXIF data added by the SDK, although it would be nice to have a way to write the JPEG representation (instead of the abstract UIImage object) out to photo album and respect any existing EXIF tags.
4) If an application wants to retain the geo tag information, it will have to maintain its own “album” inside the app – geo tag the JPEG representation of a UIImage passed from the camera UIImagePickerController, and write the data out to a JPEG file in the application’s directory; allow user to read images from local directory back into memory for manipulation/upload etc via
[UIImage imageWithData:[NSData dataWithContentsOfFile:]]
Once you start integrating with photo album on the phone, you’ll lose EXIF tags going through the SDK’s photo album interface.
All of this makes you wonder if the native Camera.app is using the same SDK photo album interface as is provided to third-party since it’s able to save photos to the photo album without losing the geo tag EXIF data. The answer is probably “NO”.