2016-10-31 8 views
5

あるUIImagePickerで画像を選択したとき、私はエラーを取得:Xcodeの8 - SWIFT 3:不明なタイプの画像フォーマットを作成するエラー

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

私はXcodeの8.1を使用していますし、スウィフト3 IすでにWeb上で検索していますが、何も私の問題を解決してくれないようです。助けてください!

ここでは、私のコードです:

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 
      } 
     } 
    } 
} 

}

+0

の可能性のある重複[Xcodeの8 - 未知のタイプの画像フォーマットの作成がエラーです](https://stackoverflow.com/questions/39009889/xcode-8-creating-an- –

答えて

0

は、あなたのピッカーデリゲートにinfoパラメータの.debugDescriptionを投稿することができますか?

func imagePickerController(_ picker: UIImagePickerController, 
         didFinishPickingMediaWithInfo info: [String : Any]) { 
print(info.debugDescription) 
... 
} 
+0

info.debugDescriptionは次のようになります。["UIImagePickerControllerMediaType":public.image、 "UIImagePickerControllerReferenceURL":assets-library://asset/asset.JPG ?id = ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext = JPG、 "UIImagePickerControllerOriginalImage": size {3000、2002} orientation 0 scale 1.000000] – ppablo

+0

let image = info [UIImagePickerControllerEditedImage] as? UIImage { //画像を保存する } 他の場合はlet image = info [UIImagePickerControllerOriginalImage] as? UIImage { //イメージを保存 } else { print( "何か問題が起こった") } – Haseeb

3

私はUIImagePickerControllerのための「自己」としてデリゲートを追加しないことで、同じ問題に直面しました。それを追加した後、ギャラリーから選択した画像を取得することができました。しかし、代理人をという自己として追加しても、画像にアクセスできるようになっても(ImageViewでの表示)、私はまだ同じエラーが発生していました。それ以上の調査の後、私はこれがちょうどバグであることを知りました、そして、決してどのような方法でもアプリに影響しません。

も参照"Creating an image format with an unknown type is an error Objective-C Xcode 8"

関連する問題