UIImagePickerControllerDelegate错误

时间:2016-12-16 10:37:37

标签: swift uiimageview swift3 uiimagepickercontroller xcode8

所以我有这个代码可以在我的画廊拍照或使用相机来改变UIImage。

@IBAction func tappedCamera() {
    print("tapped camera")

    let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet)

    let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: {
        (alert: UIAlertAction!) -> Void in

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
            self.picker.sourceType = UIImagePickerControllerSourceType.camera;
            self.picker.allowsEditing = true
            self.present(self.picker, animated: true, completion: nil)
        }

    })
    let galleryAction = UIAlertAction(title: "Gallery", style: .default, handler: {
        (alert: UIAlertAction!) -> Void in

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
            self.picker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
            self.picker.allowsEditing = true
            self.present(self.picker, animated: true, completion: nil)
        }


    })
    let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: {
        (alert: UIAlertAction!) -> Void in
        //do none
    })


    optionMenu.addAction(cameraAction)
    optionMenu.addAction(galleryAction)
    optionMenu.addAction(cancelAction)

    self.present(optionMenu, animated: true, completion: nil)

}

但每当我尝试拍摄照片或从图库中选择图像时,我总会收到此错误。

[Generic] Creating an image format with an unknown type is an error

1 个答案:

答案 0 :(得分:0)

我通过修复用户默认值解决了这个问题。因为代码中的某处我弄乱了图像,将它们转换为base64字符串,然后将其保存为用户默认值。