UIImagePickerController AllowsEditing not working

后端 未结 6 1678
余生分开走
余生分开走 2020-12-05 11:02

I am using UIImagePickerController to allow the user to take a picture. I want to allow him/her to edit it afterwards but, whatever I do, I get nothing.

Here is my co

相关标签:
6条回答
  • 2020-12-05 11:33

    SWIFT 4+

    There have been some changes after Swift 4. UIImagePickerControllerEditedImage changed to 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)
    
        }
    
    0 讨论(0)
  • 2020-12-05 11:34

    SWIFT 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:

    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)
    }
    
    0 讨论(0)
  • 2020-12-05 11:36

    There is no way to enable filters by 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.

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

    0 讨论(0)
  • 2020-12-05 11:37

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

    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.

    0 讨论(0)
  • 2020-12-05 11:39

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

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

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

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

    0 讨论(0)
  • 2020-12-05 11:40

    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)
    }
    
    0 讨论(0)
提交回复
热议问题