我已经使用下面的代码从图库或直接使用相机中挑选照片
- (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 中。我需要你的帮助
- 为我自己的应用创建自定义目录
- 想要将选择的照片保存在该自定义目录中。
我是 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/