使用UIImageWriteToSavedPhotosAlbum将图像保存到相机胶卷

时间:2010-03-29 15:00:23

标签: iphone sdk uiimagepickercontroller

用户使用相机拍摄照片后,我试图用按钮将照片保存到相机胶卷,但我不知道为什么我的照片不能保存在照片库中!

这是我的代码:

-(IBAction)savePhoto{

    UIImageWriteToSavedPhotosAlbum(img.image,nil, 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]retain];
    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];   
}

变量名称ipcUIImagePickerControllerimgUIIMageView

我的问题是什么?

1 个答案:

答案 0 :(得分:4)

首先确保您正在呼叫savePhoto。然后你可以添加一个断言来检查图像是不是nil:

- (IBAction) savePhoto {
    NSParameterAssert(img.image);
    UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
}