获取CGImageSourceRef的图像路径

时间:2011-05-18 12:18:22

标签: iphone objective-c xcode exif

嘿伙计们,我目前正试图通过UIIMagePickerController从用户选择的图像中获取EXIF数据。我似乎无法理解如何获得可用于CGImageSourceCreateWithURL((CFURLRef)someURL,nil)的路径。

当我尝试使用UIImagePickerControllerReferenceURL时,控制台会发出一个相当不错的错误:<ERROR> CGImageSourceCreateWithURLCFURLCreateDataAndPropertiesFromResource failed with error code -11.。我很难过,我开始认为我来自一个完全错误的角度,因为CGImageSourceRef类型通常用于创建图像,而我已经有UIImage。任何能够解释这个问题的人都可以随意这样做。

- (void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info {

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSLog(@"%@",[info objectForKey:UIImagePickerControllerReferenceURL]);
    //Outputs: assets-library://asset/asset.JPG?id=1000000006&ext=JPG
    CGImageSourceCreateWithURL((CFURLRef)[info objectForKey:UIImagePickerControllerReferenceURL], nil);

    //The plan is to somehow get a CGImageSourceRef object from the 
    //UIImage provided by the [info UIImagePickerControllerOriginalImage], i just don't know how to get this object,
    // for it requires the URL to the image, wich i don't seem to have.
    }

}

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; [self dismissModalViewControllerAnimated:YES]; if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){ image = [info objectForKey:UIImagePickerControllerOriginalImage]; NSLog(@"%@",[info objectForKey:UIImagePickerControllerReferenceURL]); //Outputs: assets-library://asset/asset.JPG?id=1000000006&ext=JPG CGImageSourceCreateWithURL((CFURLRef)[info objectForKey:UIImagePickerControllerReferenceURL], nil); //The plan is to somehow get a CGImageSourceRef object from the //UIImage provided by the [info UIImagePickerControllerOriginalImage], i just don't know how to get this object, // for it requires the URL to the image, wich i don't seem to have. } }

CNC中 将使用更紧张的解决方案。谢谢你的阅读。

2 个答案:

答案 0 :(得分:5)

错误代码-11表示无法识别URL方案,也就是说CFURL不知道如何处理以assets-library://开头的URL。

为什么你认为在这种情况下你需要一个CGImageSourceRef?

答案 1 :(得分:-1)

尝试使用

ALAssetRepresentation * representation = [yourAsset defaultRepresentation];

 NSDictionary * metadataDict = [[表示元数据]保留];