如何从uiimagePickerController中正确保存aN图像

时间:2013-04-10 16:11:03

标签: objective-c xcode uiviewcontroller uiimageview uiimage

你如何从imagePickerController中保存图像?我能够将图像显示到UIImageView中,但是当我尝试对图像执行任何其他操作时,图像仍为零。你可以看到我如何保存下面的图像。

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{

[self dismissViewControllerAnimated:YES completion:nil];
self.image =  [info objectForKey:UIImagePickerControllerOriginalImage]; //self.image is a UIImage property
}

1 个答案:

答案 0 :(得分:2)

[self dismissViewControllerAnimated:YES completion:nil];
self.image =  [info objectForKey:UIImagePickerControllerOriginalImage]; 

保存图像后应该关闭图像选择器,因为info是图像选择器保留的对象(并且信息存在直到图像选择器未被解除),正确的方法:

self.image =  [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];

现在你可以用图像做你想要的一切。