无法从图像NSURL获取UIImage

时间:2014-10-10 15:50:28

标签: ios xcode uiimage

从图片网址获取图片时遇到问题。这是正确的方法吗?需要帮忙。提前致谢

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage * chosenImage = info[UIImagePickerControllerEditedImage];
    NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
    NSData *dataImage = [NSData dataWithContentsOfURL:url];
    self.image.image = [UIImage imageWithData:dataImage];
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

1 个答案:

答案 0 :(得分:0)

你需要的只是:

self.image.image = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:NULL];

请注意,信息可能不包含已编辑图像的条目;