CFHipsterRef Low-Level Programming on iOS & Mac OS X

Image Metadata

Metadata is divided into several different dictionaries, which can be specified with any of the following keys:

  • kCGImagePropertyTIFFDictionary
  • kCGImagePropertyGIFDictionary
  • kCGImagePropertyJFIFDictionary
  • kCGImagePropertyExifDictionary
  • kCGImagePropertyPNGDictionary
  • kCGImagePropertyIPTCDictionary
  • kCGImagePropertyGPSDictionary
  • kCGImagePropertyRawDictionary
  • kCGImagePropertyCIFFDictionary
  • kCGImageProperty8BIMDictionary
  • kCGImagePropertyDNGDictionary
  • kCGImagePropertyExifAuxDictionary
NSDictionary *properties =
    (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(self.imageSourceRef, 0,
    NULL);

NSDictionary *EXIF = properties[(__bridge id)kCGImagePropertyExifDictionary];

if (EXIF)
{
    NSString *Fnumber = EXIF[(__bridge id)kCGImagePropertyExifFNumber];
    NSString *exposure = EXIF[(__bridge id)kCGImagePropertyExifExposureTime];
    NSString *ISO = EXIF[(__bridge id)kCGImagePropertyExifISOSpeedRatings];

    NSLog(@"Shot Information: %@ %@ %@", Fnumber, exposure, ISO);
}

NSDictionary *GPS = properties[(__bridge id)kCGImagePropertyGPSDictionary];
if (GPS)
{
    NSString *latitude = GPS[(__bridge id)kCGImagePropertyGPSLatitude];
    NSString *latitudeRef = GPS[(__bridge id)kCGImagePropertyGPSLatitudeRef];
    NSString *longitude = GPS[(__bridge id)kCGImagePropertyGPSLongitude];
    NSString *longitudeRef = GPS[(__bridge id)kCGImagePropertyGPSLongitudeRef];

    NSLog(@"GPS: %@ %@ / %@ %@", latitude, latitudeRef, longitude, longitudeRef);
}