gpt4 book ai didi

ios - UIImagePickercontroller 不使用按钮不保存

转载 作者:行者123 更新时间:2023-12-01 18:57:59 24 4
gpt4 key购买 nike

我正在使用 UIImagePickerController 拍照并保存到照片库。当我启动选择器时,它有拍照按钮和拍照后取消按钮,它显示 2 个按钮 Retake & use,如果我使用,使用按钮,然后只将图像保存到相册,但保存后我无法转到上一页或关闭选择器。

-(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];

}

最佳答案

只需关闭您的 View Controller 。像这样,更新你的 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];


}

关于ios - UIImagePickercontroller 不使用按钮不保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25360304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com