如何从UIImagePickerControllerReferenceURL获取UIImage

时间:2012-07-17 13:30:40

标签: objective-c ios cocoa

我正在努力弄清楚如何从UIImagePickerControllerReferenceURL获取图像(我知道我可以直接从UIImagePickerControllerOriginalImage获取它,但是,我有理由不想这样做)。这就是我所拥有的

/* 
 *   Responds when an image is selected (from browsing)
 */
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{        
        UIImage *image = [self obtainImageAtURLPath:[info objectForKey:UIImagePickerControllerReferenceURL]];
        if(!image) return;
        //...more code here
}
- (UIImage *) obtainImageAtURLPath:(NSURL *) urlPath
{
    UIImage *image = [UIImage imageWithContentsOfFile:[urlPath path]];
    return image;
}

然而,当我这样做时,我总是得到nil而不是我的形象。 urlPath存在;但是,它不希望转换为UIImage。请帮助。

如果我打印NSLog(@"%@", urlPath),我会assets-library://asset/asset.JPG?id=53784678-BD17-4EE4-9A96-601B81012AFE&ext=JPG

如果我打印NSLog(@"%@", [urlPath path]),我会/asset.JPG

1 个答案:

答案 0 :(得分:0)

我在这里回答了类似的问题:name of the picked image xcode。您应该使用ALAssetsLibrary使用urlPath

加载该图片资源