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

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

    What I did was that once I got the image from didFinishPickingMediaWithInfo, I called:

    func prepareImageForSaving(image:UIImage) {
        // create NSData from UIImage
        guard let imageData = UIImageJPEGRepresentation(image, 1) else {
            // handle failed conversion
            print("jpg error")
            return
        }
    
        self.saveImage(imageData: imageData as NSData)
    }
    
    func saveImage(imageData: NSData) {
        imageDatas = imageData
    }
    

    to save it in NSData format.

    The console still warned me on "[Generic] Creating an image format with an unknown type is an error" but at least my imageView gets updated to the selected image rather than showing the previous one from viewDidLoad.

提交回复
热议问题