> > Given a URL to an image I currently do this to grab image properties > (ignoring error handling to simplify the example code) > > let imgRef = CGImageSourceCreateWithURL(url as CFURL, nil) > let imgProps = CGImageSourceCopyPropertiesAtIndex(imgRef, 0, nil) as > NSDictionary? > let GPSDictionary = kCGImagePropertyGPSDictionary as NSString > let gpsData = imgProps[GPSDictionary] as? [String: AnyObject] >
I am not sure this will solve the problem, but the following code works for me, albeit I have not tested it on CR3 images. Also , you should take it with a grain of salt, because I am not sure about the correctness of the Retain/Release's under ARC. If you want, you can send my an example CR3 file, and I can check whether my code will extract more info. Best regards, Gabriel // get meta data CFDictionaryRef gps_dict; success = CFDictionaryGetValueIfPresent( fileProps, kCGImagePropertyGPSDictionary, (const void **) & gps_dict ); if ( success && gps_dict ) { CFRetain( gps_dict ); CFNumberRef gps_long = NULL, gps_lat = NULL; success = CFDictionaryGetValueIfPresent( gps_dict, kCGImagePropertyGPSLongitude, (const void **) & gps_long ); success |= CFDictionaryGetValueIfPresent( gps_dict, kCGImagePropertyGPSLatitude, (const void **) & gps_lat ); CFStringRef gps_longref = NULL, gps_latref = NULL; success |= CFDictionaryGetValueIfPresent( gps_dict, kCGImagePropertyGPSLongitudeRef, (const void **) & gps_longref ); success |= CFDictionaryGetValueIfPresent( gps_dict, kCGImagePropertyGPSLatitudeRef, (const void **) & gps_latref ); if ( success ) { success = CFNumberGetValue( gps_lat, kCFNumberDoubleType, imglat ); if ( success && gps_latref && CFStringCompare(gps_latref, CFSTR("S"), 0) == kCFCompareEqualTo ) *imglat = - *imglat; success = CFNumberGetValue( gps_long, kCFNumberDoubleType, imglong ); if ( success && gps_longref && CFStringCompare(gps_longref, CFSTR("W"), 0) == kCFCompareEqualTo ) *imglong = - *imglong; } CFRelease( gps_dict ); } // retreieve IPTC metadata CFDictionaryRef iptc_dict; success = CFDictionaryGetValueIfPresent( fileProps, kCGImagePropertyIPTCDictionary, (const void **) & iptc_dict ); if ( success && iptc_dict ) { CFRetain( iptc_dict ); CFArrayRef img_keywords = NULL; // contrary to the doc, it is an array, not a string! success = CFDictionaryGetValueIfPresent( iptc_dict, kCGImagePropertyIPTCKeywords, (const void **) & img_keywords ); if ( img_keywords ) { NSArray * imgkeywords = (__bridge NSArray * _Nonnull) img_keywords; *imgkeyword = [[NSString alloc] initWithString: imgkeywords[0] ]; } CFStringRef caption = NULL; success = CFDictionaryGetValueIfPresent( iptc_dict, kCGImagePropertyIPTCCaptionAbstract, (const void **) & caption ); if ( success && caption ) { *imgcaption = [[NSString alloc] initWithString: (__bridge NSString * _Nonnull)(caption)]; } CFRelease( iptc_dict ); } // retreieve EXIF metadata CFDictionaryRef exif_dict; success = CFDictionaryGetValueIfPresent( fileProps, kCGImagePropertyExifDictionary, (const void **) & exif_dict ); if ( success && exif_dict ) { CFRetain( exif_dict ); CFStringRef dateref = NULL; success = CFDictionaryGetValueIfPresent( exif_dict, kCGImagePropertyExifDateTimeOriginal, (const void **) & dateref ); if ( success ) { *date = [[NSString alloc] initWithString: (__bridge NSString * _Nonnull)(dateref)]; } CFRelease( exif_dict ); } _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com