使用ImageIO从Image获取EXIF数据

时间:2011-12-26 12:29:39

标签: ios exif error-code

在我的应用程序中,我想从ImagePickerController读取图像元数据。 我试过这样:

NSURL* imgURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
NSLog(@"%@", imgURL);

CGImageSourceRef mySourceRef = CGImageSourceCreateWithURL((__bridge CFURLRef)imgURL, NULL);
NSDictionary *myMetadata = (__bridge 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]);

但我收到了ImageIO错误:

  

ImageIO:CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource失败,错误代码为-11。

我没有找到有关错误代码-11的文档,只有约-15(坏参数)。 我希望你能有一个解决方案。

电贺 s4lfish

0 个答案:

没有答案