1

感谢您的阅读,这是我的问题。我正在尝试保存一张图片(我使用 UIImagePickerController 方法拍摄的),尽管我有一个错误。错误是“不响应选择器图像:didFinishSavingWithError:contextInfo :)

我在其他地方读到这与将实例方法更改为类方法有关(但我是菜鸟,不知道这意味着什么。)这是我的代码:D。

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



// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Save image 
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

我被告知这与 UIImageWriteToSavedPhotosAlbum 方法中的“Self”有关。

4

2 回答 2

3

使用此代码保存您选择的图像:

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
 UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 UIImageWriteToSavedPhotosAlbum(image,self,  
                                   @selector(image:finishedSavingWithError:contextInfo:),
                                   nil);
}

并添加此功能。

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo: (void *)contextInfo
{
if (error != nil) 
 {
    NSLog(@"Image Can not be saved");
 } 
 else 
 {
    NSLog(@"Successfully saved Image");
 }
}
于 2013-02-05T07:50:40.590 回答
2

您的班级(自我)不响应选择器image:didFinishSavingWithError:contextInfo:。你应该实现这个选择器。像这样的东西

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error != nil) {
        NSLog(@"Couldn't save image");
    } else {
        NSLog(@"Saved image");
    }
}
于 2013-01-29T07:02:16.123 回答