gpt4 book ai didi

iphone - 如何保存拍摄的照片

转载 作者:行者123 更新时间:2023-11-28 20:17:03 25 4
gpt4 key购买 nike

我想保存我在应用程序中拍摄的照片。我想保存图片,这样即使我关闭应用程序,图片仍会保存。这是我到目前为止编写的代码

-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil];
}

- (IBAction)ChooseExisting {
picker2 = [[UIImagePickerController alloc]init];
picker2.delegate = self;
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:nil];
}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageview setImage:image];
[self dismissViewControllerAnimated:YES completion:nil];

}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}

我应该如何让应用程序保存我拍摄的照片并显示它。

最佳答案

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

UIImage * imageToSave = [UIImage imageNamed:@"Icon.png"];
NSData * binaryImageData = UIImagePNGRepresentation(imageToSave);

[binaryImageData writeToFile:[basePath stringByAppendingPathComponent:@"myfile.png"] atomically:YES];

Copied from here

您可能需要编辑带有 imageToSave 变量的行,并将其更改为从相机获取的 UIImage 变量。

关于iphone - 如何保存拍摄的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17667508/

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