gpt4 book ai didi

ios - 在 iPhone 中创建自定义图片库

转载 作者:行者123 更新时间:2023-11-28 22:40:01 25 4
gpt4 key购买 nike

我已经使用下面的代码从图库或直接使用相机中挑选照片

- (void)actionSheet:(UIActionSheet *)actionSheet 
clickedButtonAtIndex:(NSInteger)buttonIndex {

UIImagePickerController *imagePickerController =
[[UIImagePickerController alloc]init];

imagePickerController.delegate = self;
if (buttonIndex == 0) {
photoButtonNum=0;
[self presentViewController:imagePickerController
animated:YES
completion:nil];
imagePickerController.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
} else if (buttonIndex == 1) {
photoButtonNum=1;
[self presentViewController:imagePickerController
animated:YES
completion:nil];
imagePickerController.sourceType =
UIImagePickerControllerSourceTypeCamera;
}
}

我正在寻找创建我自己的应用程序的自定义目录(文件夹)以将挑选的照片保存在 iPhone 中。我需要你的帮助

  1. 为我自己的应用创建自定义目录
  2. 想要将选择的照片保存在该自定义目录中。

我是 iPhone 开发的新手,期待您的宝贵帮助。提前致谢。

最佳答案

本站有助于您创建和保存Photo in your Directory

你也可以使用下面的代码。

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *pickedImage =
[info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation(pickedImage);

NSString *documentsDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES) lastObject];
NSString *path = [documentsDirectory
stringByAppendingPathComponent:@"imageName.png"];

NSError * error = nil;
[imageData writeToFile:storePath options:NSDataWritingAtomic error:&error];

if (error != nil) {
NSLog(@"Error: %@", error);
return;
}
}

关于ios - 在 iPhone 中创建自定义图片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14805832/

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