Getting EXIF data from images on iOS
Author: The Man
Working on a project that needed to show images with their information so looked into extracting EXIF data from the image itself rather than banging it into a db. Note this requires jpg files as png’s didn’t seem to work.
View Code OBJC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | NSString *myPath = [[NSBundle mainBundle] pathForResource:@"IMG_2733" ofType:@"JPG"]; NSURL *myURL = [NSURL fileURLWithPath:myPath]; CGImageSourceRef mySourceRef = CGImageSourceCreateWithURL((CFURLRef)myURL, NULL); NSDictionary *myMetadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL); NSDictionary *exifDic = [myMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]; NSDictionary *tiffDic = [myMetadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary]; NSLog(@"exifDic properties: %@", myMetadata); //all data float rawShutterSpeed = [[exifDic objectForKey:(NSString *)kCGImagePropertyExifExposureTime] floatValue]; int decShutterSpeed = (1 / rawShutterSpeed); NSLog(@"Camera %@",[tiffDic objectForKey:(NSString *)kCGImagePropertyTIFFModel]); NSLog(@"Focal Length %@mm",[exifDic objectForKey:(NSString *)kCGImagePropertyExifFocalLength]); NSLog(@"Shutter Speed %@", [NSString stringWithFormat:@"1/%d", decShutterSpeed]); NSLog(@"Aperture f/%@",[exifDic objectForKey:(NSString *)kCGImagePropertyExifFNumber]); NSNumber *ExifISOSpeed = [[exifDic objectForKey:(NSString*)kCGImagePropertyExifISOSpeedRatings] objectAtIndex:0]; NSLog(@"ISO %i",[ExifISOSpeed integerValue]); NSLog(@"Taken %@",[exifDic objectForKey:(NSString*)kCGImagePropertyExifDateTimeDigitized]); |
Obviously change the image name and be aware that images loaded in a UIImageView seem to have their EXIF data stripped out.






July 30th, 2011 at 2:37 am
NSLog(@”Shutter Speed %@”, [NSString stringWithFormat:@"1/%d", decShutterSpeed]);
should be written as
NSLog(@”Shutter Speed 1/%d”, decShutterSpeed);
December 31st, 2011 at 8:18 am
Very useful, thank you! Maybe you should add that the ImageIO.framework is required and you must import both and
April 4th, 2012 at 5:19 pm
how can I get the ImageIO.framework ?
I’ve read that it doesn’t exist for iphone!!!! Can anyone show me the way?
I’m pretty new to Iphone dev. I need to extract EXIF geolocation data in my app.
April 4th, 2012 at 6:48 pm
Have a look at the screenshot here which shows where the frameworks are added.