Ios UIImagePickercontroller未使用按钮保存
我正在使用UIImagePickerController拍摄照片并保存到照片库。当我启动picker时,它有拍照按钮和拍照后取消按钮,它显示2个按钮Retake&use,如果我使用,则使用按钮,然后仅将图像保存到相册,但保存后我无法转到上一页或关闭pickerIos UIImagePickercontroller未使用按钮保存,ios,objective-c,uiimagepickercontroller,Ios,Objective C,Uiimagepickercontroller,我正在使用UIImagePickerController拍摄照片并保存到照片库。当我启动picker时,它有拍照按钮和拍照后取消按钮,它显示2个按钮Retake&use,如果我使用,则使用按钮,然后仅将图像保存到相册,但保存后我无法转到上一页或关闭picker -(void)takepicture:(id)sender{ // Create image picker controller UIImagePickerController *imagePicker = [[UIImagePi
-(void)takepicture:(id)sender{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
// [self performSelector:@selector(onTimer_Loadpicture:) withObject:nil afterDelay:0.5];
}
- (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(image, nil, nil, nil);
[picker release];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
[self performSelector:@selector(onTimer_Loadpicture:) withObject:nil afterDelay:0.5];
}
只需关闭视图控制器。像这样,用info方法更新您的didFinishPickingMediaWithInfo
- (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(image, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
您并不是要解除视图控制器。您应该这样做,如果不需要此代码的一部分,则您可以决定是否在imageView中检查图像。如果不想检查,则只需删除if部分并使用else部分的代码
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editingInfo{
[self dismissModalViewControllerAnimated:YES];
_imgview.image = [editingInfo valueForKey:@"UIImagePickerControllerOriginalImage"];
if(_imgview==nil){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Angry!!!" message:@"Vennligst velg et bilde!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
else{
_imgview.image = img;
imageData=[self compressImage:img];
[picker dismissModalViewControllerAnimated:YES];
_lblname.hidden=true;
}
return;
}
您没有在imagePickerController:didFinishPickingMediaWithInfo中解除视图控制器:您的意思是我是否需要添加[self-DismissModalViewController:Imaged:YES];?是的,用户拍照后,您需要关闭视图。您可能还需要在image:didfishsavingwitherror:contextInfo: