gpt4 book ai didi

ios - 将拍摄的图像保存在照片库中

转载 作者:行者123 更新时间:2023-11-29 02:58:30 24 4
gpt4 key购买 nike

我已经编写了这个程序来在选择 uiimage 时保存图像,但是我需要编写代码来 捕获图像时将图像保存在 UIImagePickerControllerSourceTypePhotoLibrary 中
仅由相机拍摄。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if([info objectForKey:@"UIImagePickerControllerOriginalImage"])
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
PhotoViewController *photoVC=[[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
photoVC.photoImage=image;
photoVC.photoDelegate=self;
[self.navigationController pushViewController:photoVC animated:YES];
}


}

最佳答案

我想这会对你有帮助。请试试这个。

这是使用相机拍摄图像的代码:

 UIImagePickerController *myImagePickerController = [[UIImagePickerController alloc]init];
myImagePickerController.delegate = self;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if (YES == [UIImagePickerController isSourceTypeAvailable:sourceType])
{
myImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:myImagePickerController.view];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning !!" message:@"Camera is not available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}

此代码用于在照片库中保存图像:

  UIImage *img = [UIImage imageNamed:@"image.png"]; // This is your after taking photo
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);


- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error != NULL)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:[[error localizedDescription] capitalizedString] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sucesses !!" message:@"Your image has been saved sucessefully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert setTag:100];
[alert release];
}

}

关于ios - 将拍摄的图像保存在照片库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581305/

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