简体   繁体   English

如何在 Xcode 中显示照片库图像?

[英]How to display photo library image in Xcode?

My objective-c code is erroring out with the Code=13 error, and does not display either the cameras photo or a library's image in an image view.我的objective-c 代码出错,出现Code=13 错误,并且在图像视图中不显示相机照片或库图像。

I'M Using Xcode 10.1, deployment target 12.0, and I'm going off example from UIImagePickerController not picking image in iOS 9我正在使用 Xcode 10.1,部署目标为 12.0,我将离开UIImagePickerController 的示例, 而不是在 iOS 9 中选择图像

I have two problems:我有两个问题:

1) Even though I add in "Privacy - Photo Library Usage Description | We want to use the library" in the p-list, it still gives me this error: 1)即使我在 p-list 中添加了“隐私 - 照片库使用说明 | 我们想要使用该库”,它仍然给我这个错误:

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} [发现] 发现扩展时遇到的错误:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

What am I doing wrong?我究竟做错了什么?

2) I can't get the image to show up in the LoveImage view. 2) 我无法在 LoveImage 视图中显示图像。 What am I doing wrong here?我在这里做错了什么?

Below is .m file:下面是 .m 文件:

-(IBAction)imagepickertapped:(id)sender { 
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Attach image" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* pickFromGallery = [UIAlertAction actionWithTitle:@"Take a photo"
                                                          style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction * action) {
                                                            if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                                                            {
                                                                UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                                                                picker.delegate = self;
                                                                [self presentViewController:picker animated:YES completion:NULL];
                                                            }

                                                        }];
UIAlertAction* takeAPicture = [UIAlertAction actionWithTitle:@"Choose from gallery"
style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                                                         picker.delegate = self;
                                                         [self presentViewController:picker animated:YES completion:NULL];
                                                     }];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel"
                                         style:UIAlertActionStyleCancel
                                               handler:^(UIAlertAction * action) {
                                               }];

[alertController addAction:pickFromGallery];
[alertController addAction:takeAPicture];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil]; }

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
UIImage *LoveImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
self.LoveImage = info[UIImagePickerControllerOriginalImage];}

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

Change your didfinish method code to below.将您的 didfinish 方法代码更改为以下内容。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    UIImage *LoveImage = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
    self.LoveImage.image = LoveImage;
}

LoveImage is an image view. LoveImage 是一个图像视图。 We can't assign an image to it directly.我们不能直接为其分配图像。 It has an image property so we have to set its image property.它有一个image属性,所以我们必须设置它的image属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xcode / tesseract,使用图片库中的图像 - xcode/tesseract, use image from photo library 将照片从照片库导入Xcode中的应用程序 - Importing image from photo library into an app in xcode 如何在 Cordova 中显示照片库权限对话框? - How to display photo library permissions dialog in Cordova? 如何在从图片库拍摄的uiimageview中显示拾取的图像到另一个视图控制器中的另一个uiimageview中? - How to display picked image in a uiimageview taken from the photo library to another uiimageview in a different view controller? 如何全屏显示照片库中的任何图像? - How can I display any image from photo library at full screen? 如何从iOS照片库中获取图像并将其显示在UIWebView中 - How do I get an image from the iOS photo library and display it in UIWebView 如何将图像从 imageView 保存到照片库? - How to save image from imageView to Photo Library? Phonegap 1.3 captureImage到照片库并在HTML / App界面中显示图像 - Phonegap 1.3 captureImage to Photo Library and display image in HTML/App interface 使用xcode和swift从照片库中选择要显示到Apple Watch上的图像视图的图像 - Selecting an image from the photo library to be displayed to a image view on the apple watch using xcode and swift 如何将图像URL保存到照片库,然后使用保存的图像 - How to save image URL to photo library and subsequently use the saved image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM