UIImageWriteToSavedPhotosAlbum问题

时间:2010-03-27 10:11:43

标签: iphone sdk

我尝试使用按钮拍照后从相机保存照片。

这是我的代码:

-(IBAction)savePhoto{

    UIImageWriteToSavedPhotosAlbum(img.image, nil, nil);    

}

-(IBAction)takePic {

    ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentModalViewController:ipc animated:YES];
}

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

    img.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];
}

但我不知道为什么不保存任何东西!

2 个答案:

答案 0 :(得分:1)

我怀疑你的图像在保存前已经发布了:

img.image = [info objectForKey:UIImagePickerControllerOriginalImage];

上面的行返回一个自动释放的对象。我建议您保留下图所示的图像,然后在保存图像时将其释放。

img.image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];

答案 1 :(得分:0)

检索图片后,在[self savePhoto]内致电-imagePickerController:didFinishPickingMediaWithInfo: