UIImage+MetaData (+ iPhone camera roll) [was] still a huge problem [in iOS4.0]Posted: July 7, 2010 | |
The Image IO framework allows us to add meta data to the images but surprisingly when the image is saved to the camera roll, the meta data is stripped off.
Is this the bug or the feature :-).
I am not sure if you can add it or not, I just remembered seeing properties of CGImageRef that included GPS location and EXIF data. The UIImage class strips all excess data besides rotation information and a few other things. That means it strips the location information. If you could add the GPS coordinates directly to the CGImageRef and save that, it should work.
Nope, CGImages don’t have metadata either. CGImageSource and CGImageDestination objects in the ImageIO framework (newly brought from OS X for iOS4?) handle metadata out-of-band from the image as part of reading & writing image files (& similar data sources). Camera.app can write metadata to the camera roll but I suspect its using then using ImageIO (or private equivalent) to write a file directly to camera roll’s directory rather than using the same API’s we have to use, grr.
My app takes pictures with UIImagePicker and I’ve seen people in the same boat complain that metadata is getting stripped from the image by getting converted to a UIImage. But rather a problem of the metadata being stripped, it’s probably never collected at all when the picture taken.
I think the UIImagePicker and AVFoundation + AssetsLibrary really need to:
1. incorporate Camera.app’s metadata generation code
2. make the camera’s metadata dictionary accessible for apps to inspect and tinker with, then write out with ImageIO
3. allow metadata dictionary to be passed to a methods like ALAssetsLibrary’s writeImageToSavedPhotosAlbum:orientation:.., or maybe support importing a whole image file into the camera roll, one that an app has written to complete with metadata. This would be similar to the interfaces for writing video files to the camera roll
UPDATE: Apple has extended UIImagePickerController & ALAssetsLibrary in iOS4.1 to satisfy every problem I had with photo metadata in iOS4. Yay! These changes aren’t mentioned in the 4.1 Release Notes but can be seen by searching for “metadata” in the API Diffs http://developer.apple.com/library/ios/#releasenotes/General/iOS41APIDiffs/index.html
UPDATE pasting in this elaboration I wrote elsewhere: There’s been a way to get metadata from AVFoundation since 4.0 by calling CMCopyDictionaryOfAttachments on the imageBuffer, see code in this StackOverflow thread, but also now in 4.1 the info dict UIImagePickerController passes to you with the photo has the metadata dict in it, get it using key UIImagePickerControllerMediaMetadata. There’s new methods of ALAssetsLibrary since 4.1 that accept one of these metadata dicts along with the photos save, a little complex that calling UIImageWriteToSavedPhotosAlbum, but not by much. I keep my ALAssetsLibrary instance around for the duration of my app, not sure if that’s kosher but it seems to work for now. (Note to self: look that up soon)