[英]Save image to camera roll with 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 !! 用户使用相机拍摄照片后,我试图用按钮保存照片到相机胶卷,但我不知道为什么我的照片不能保存在照片库!
Here is my code : 这是我的代码:
-(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];
}
Variable name ipc
is UIImagePickerController
and img
is UIIMageView
. 变量名
ipc
是UIImagePickerController
, img
是UIIMageView
。
what's my problem ? 我的问题是什么?
First make sure you are calling savePhoto
. 首先确保您正在调用
savePhoto
。 Then you can add an assertion to check that the image is not nil: 然后你可以添加一个断言来检查图像是不是nil:
- (IBAction) savePhoto {
NSParameterAssert(img.image);
UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.