imagePickerController:didFinishPickingMediaWithInfo问题

时间:2011-03-02 13:55:36

标签: iphone uiimage uiimagepickercontroller

如果我不编辑图片会得到什么结果?

(image = nil ? or image = OriginalImage) 

picker.allowsImageEditing = YES;

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
}

1 个答案:

答案 0 :(得分:5)

字典中不存在密钥,或者它与原始图像相同。最简单的做法就是防御性地编码:

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];

这样,即使不同版本的iOS上的行为不同,您仍然会得到理智的结果。