无法在Cocoa中从EXIF获取创建图像的日期

时间:2014-05-02 18:05:49

标签: cocoa date exif

我遇到了麻烦。当我从image获取日期时,值为NULL。 imagePropertiesDictionary不包含键kCGImagePropertyExifDateTimeOriginal。 我是从Apple开发库中获取此示例的。

CGImageSourceRef myImageSource;

myImageSource = CGImageSourceCreateWithURL(url, NULL);

CFDictionaryRef imagePropertiesDictionary;

imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL);

NSString *dateTaken = (NSString *)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDateTimeOriginal);
NSLog(@"%@",dateTaken);

CFRelease(imagePropertiesDictionary);
CFRelease(myImageSource);

_textbox.stringValue = [NSString stringWithFormat:@"%@", dateTaken];

1 个答案:

答案 0 :(得分:1)

您需要检查EXIF属性字典:

CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSDictionary *exif = [(NSDictionary *)props objectForKey : (NSString *)kCGImagePropertyExifDictionary];
NSString *dateTimeString = [exif objectForKey:(NSString *)kCGImagePropertyExifDateTimeOriginal];