将相册中的图像分配给变量Objective-c

时间:2015-03-02 00:46:35

标签: ios objective-c

我使用以下代码从相册中获取图片:

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:picker animated:YES completion:nil];}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];}

请有人帮我分配这个图像到变量吗?我想稍后使用stackblur来模糊它:

UIImage *newIma=[oldIma stackBlur:radius];

提前致谢!

1 个答案:

答案 0 :(得分:1)

在您获取用户选择的图像时设置UIImage

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:nil];
    // Create the UIImage in your @implementation and set it here
    myImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    myImageView.image = myImage;
}