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

后端 未结 23 1827
长发绾君心
长发绾君心 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:47

    Be sure to also include theUINavigationControllerDelegate delegate. This solved the issue for me.

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

    Add this to viewDidload()

    imagepicker.delegate = self
    
    0 讨论(0)
  • 2020-11-28 09:51

    Below mentioned code did solve the problem for me -

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            imagePost.image = image
        } else{
            print("Something went wrong")
        }
    
        self.dismiss(animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2020-11-28 09:51

    Below code did solve the problem:

    If user perform changes to selected image pull only that image otherwise pull original image source without any changes and finally dismiss image picker view controller.

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

    I found the default images in the photo library could couse this problem. If you drag an image from your computor onto the simulator and choose it. this problem is solved

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