“Creating an image format with an unknown type is an error” with UIImagePickerController

后端 未结 23 1828
长发绾君心
长发绾君心 2020-11-28 09:08

While choosing an image from the image picker in iOS 10 Swift 3 I am getting an error - Creating an image format with an unknown type is an error



        
相关标签:
23条回答
  • 2020-11-28 09:37

    The accepted solution by Jeetendra Choudhary works.Although in Xcode 8 with Swift 3 , I noticed that it generates a warning : Instance method 'imagePickerController(_:didFinishPickingMediaWithInfo:)' nearly matches optional requirement 'imagePickerController(_:didFinishPickingMediaWithInfo:)' of protocol 'UIImagePickerControllerDelegate'

    and suggests to add either @nonobjc or private keyword to silence the warning.If you silence the warning using these suggestions , the solution no longer works though.

    0 讨论(0)
  • 2020-11-28 09:37

    This worked for me:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            imageView.image = image
            self.dismiss(animated: true, completion: nil)
        }
    }
    
    0 讨论(0)
  • 2020-11-28 09:39

    Change didFinishPickingMediaWithInfo info: [String : AnyObject] , to didFinishPickingMediaWithInfo info: [String : Any]

    0 讨论(0)
  • 2020-11-28 09:42
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    
             let image = info[UIImagePickerControllerOriginalImage] as? UIImage
            self.dismiss(animated: true, completion: nil)
            self.imageTook.image = image
        }
    
    0 讨论(0)
  • 2020-11-28 09:42

    This worked for me. Just copy and paste it exactly.

        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        // The info dictionary contains multiple representations of the image, and this uses the original.
            let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    
        // Set photoImageView to display the selected image.
         photoImageView.image = selectedImage
    
        // Dismiss the picker.
        dismiss(animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2020-11-28 09:47

    I think you are missing a connection between photoImageView and the image.

    Take a look my screenshots below:

    0 讨论(0)
提交回复
热议问题