使用UIImageWriteToSavedPhotosAlbum将图像保存到相机胶卷
问题描述:
用户使用相机拍摄照片后,我试图用按钮将照片保存到相机胶卷,但我不知道为什么我的照片不能保存在照片库中!
I am trying to save a photo with a button to camera roll after user capture a picture with Camera , but I don't know why my picture doesn't save at photo library !!
这是我的代码:
-(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];
}
变量名称 ipc
是 UIImagePickerController
和 img
是 UIIMageView
。
我的问题是什么?
答
首先确保你打电话给 savePhoto
。然后你可以添加一个断言来检查图像是不是nil:
First make sure you are calling savePhoto
. Then you can add an assertion to check that the image is not nil:
- (IBAction) savePhoto {
NSParameterAssert(img.image);
UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
}