ios UIImagePickerController 允许编辑不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21024648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:03:31  来源:igfitidea点击:

UIImagePickerController AllowsEditing not working

iosiphonexamarin.iosuiimagepickercontrollerxamarin

提问by Amit Raz

I am using UIImagePickerController to allow the user to take a picture. I want to allow him to edit it afterwards but whatever I am doing i get nothing. Here is my code (I am using Xamarin):

我正在使用 UIImagePickerController 来允许用户拍照。我想让他事后编辑它,但无论我在做什么,我都一无所获。这是我的代码(我使用的是 Xamarin):

UIImagePickerController imagePicker = new UIImagePickerController ();
                // set our source to the camera
                imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
                // set what media types
                //imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.Camera);
                // show the camera controls
                imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
                imagePicker.ShowsCameraControls = true;
                imagePicker.AllowsEditing = true;
                imagePicker.SetEditing (true,true);
                imagePicker.PreferredContentSize = new SizeF(900,600);
                imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo;
                imagePicker.Title="taste.eat. image";
                // attach the delegate
                imagePicker.Delegate = new ImagePickerDelegate();
                // show the picker
                NavigationController.PresentViewController(imagePicker, true,null);

Am I missing something?

我错过了什么吗?

EDIT:

编辑:

I have followed the tutorial and I am getting to the screen with the rectangle, but if i pan or zoom it just snaps back to the center once I lift my finger. Is it possible to get to this screen from the photos application?

我已经按照教程操作,我正在使用矩形进入屏幕,但是如果我平移或缩放它,一旦我抬起手指,它就会回到中心。是否可以从照片应用程序进入此屏幕?

Image from the photos application

来自照片应用程序的图像

回答by Aditya Mathur

When using UIImagePickerController's delegatemethod - imagePickerController:didFinishPickingMediaWithInfo:, we get the image using

使用UIImagePickerController's delegate方法 - 时imagePickerController:didFinishPickingMediaWithInfo:,我们使用

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

This code will always return the original image, even if editing is ON.

此代码将始终返回原始图像,即使编辑处于开启状态。

Try using

尝试使用

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

This will return the edited image if editing is ON.

如果编辑打开,这将返回编辑后的图像。

Hope this helps.

希望这可以帮助。

回答by Hyman

The AllowsEditingproperty simply allows the user to crop to a square if picking an image and trim the video if picking a video.

AllowsEditing属性仅允许用户在选择图像时裁剪为正方形,并在选择视频时修剪视频。

Any other functionality needs to be implemented with custom UI and code.

任何其他功能都需要使用自定义 UI 和代码来实现。

See this question:iPhone SDK - How to customize the crop rect in UIImagePickerController with allowsEditing on?

请参阅此问题:iPhone SDK - 如何在启用允许编辑的情况下自定义 UIImagePickerController 中的裁剪矩形?

What you are showing in the screenshot is not part of UIImagePickerController, unfortunately

UIImagePickerController不幸的是,您在屏幕截图中显示的内容不属于

回答by A.J. Hernandez

SWIFT 3

斯威夫特 3

I was having a hard time returning the cropped image (simple mistake on my end). Instead of using UIImagePickerControllerOriginalImage, you need UIImagePickerControllerEditedImage. See below:

我很难返回裁剪后的图像(我的最后一个简单的错误)。而不是使用 UIImagePickerControllerOriginalImage,你需要 UIImagePickerControllerEditedImage。见下文:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    // The info dictionary contains multiple representations of the image, and this uses the cropped image.
    let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage

    // Set yourImageView to display the selected image.
    yourImage.image = selectedImage

    // Dismiss the picker.
    dismiss(animated: true, completion: nil)
}

回答by Hasan Can

SWIFT 4+

斯威夫特 4+

There have been some changes after Swift 4. UIImagePickerControllerEditedImagechanged to UIImagePickerController.InfoKey.editedImage.

Swift 4.UIImagePickerControllerEditedImage改为UIImagePickerController.InfoKey.editedImage.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        let selectedImage = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
        imageView.image = selectedImage
        dismiss(animated: true, completion: nil)

    }

回答by Md. Ibrahim

It will be work like this way.

它会像这样工作。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage

    userPhoto.image = selectedImage

    dismiss(animated: true, completion: nil)
}

回答by Tariq

There is no way to enable filtersby just changing property like allowsEditing = YES. It will only display a cropping tool. As per your screenshot it's look like you have integrated some buggy open source library and without looking at the source code it would be difficult to fix your center cropping bug.

没有办法enable filters仅仅改变像allowsEditing = YES. 它只会显示裁剪工具。根据您的屏幕截图,您似乎集成了一些有问题的开源库,如果不查看源代码,则很难修复中心裁剪错误。

Better to post some concrete detail about your implementation or switch to standard open source library.

最好发布一些有关您的实现的具体细节或切换到标准的开源库