我遇到了麻烦。当我从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];
答案 0 :(得分:1)
您需要检查EXIF属性字典:
CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSDictionary *exif = [(NSDictionary *)props objectForKey : (NSString *)kCGImagePropertyExifDictionary];
NSString *dateTimeString = [exif objectForKey:(NSString *)kCGImagePropertyExifDateTimeOriginal];