5

UIImagePicker で画像を選択するとエラーが発生します。

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

私は Xcode 8.1 と Swift 3 を使用しています。すでにウェブ全体を検索しましたが、問題を解決できるものはないようです。助けてください!

これが私のコードです:

class TabBarController: UITabBarController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

var isSelected: Bool = false
var imgPicker: UIImagePickerController = UIImagePickerController()

override func viewDidLoad() {
    super.viewDidLoad()
    //imgPicker = UIImagePickerController()
    imgPicker.delegate = self
    imgPicker.allowsEditing = false
    imgPicker.sourceType = .photoLibrary
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    imgPicker.dismiss(animated: true, completion: nil)

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        self.performSegue(withIdentifier: "toPostPicture", sender: image)
    }
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    dismiss(animated: true, completion: nil)
}

func askImagePickerSource(sender: UIViewController) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

        let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: { (action: UIAlertAction) in
            self.imgPicker.sourceType = .camera
            self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera)!
            sender.present(self.imgPicker, animated: true, completion: nil)
        })
        let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default, handler: { (action: UIAlertAction) in
            self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
            sender.present(self.imgPicker, animated: true, completion: nil)
        })
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (UIAlertAction) in
            sender.dismiss(animated: true, completion: nil)
        }

        alert.addAction(cameraAction)
        alert.addAction(photoLibraryAction)
        alert.addAction(cancelAction)

        sender.present(alert, animated: true, completion: nil)
    } else {
        self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
        sender.present(self.imgPicker, animated: true, completion: nil)
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "toPostPicture" {
        if let postPictureVC = segue.destination as? PostPictureVC {
            if let image = sender as? UIImage {
                postPictureVC.image = image
            }
        }
    }
}

}

4

2 に答える 2

0

ピッカーデリゲート.debugDescriptionにパラメーターを投稿できますか?info

func imagePickerController(_ picker: UIImagePickerController,
                       didFinishPickingMediaWithInfo info: [String : Any]) {
print(info.debugDescription)
...
}
于 2016-11-02T06:43:57.487 に答える