使用UI
ImagePicker选择图像时出错:
[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",handler: { (action: UIAlertAction) in self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker,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,completion: nil) } else { self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker,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 } } } }
}
我通过不为UIImagePickerController添加委托作为’self’来面对同样的问题.添加后,我能够从图库中获取所选图像.但即使将委托添加为自己并能够访问图像(在ImageView上显示),我仍然得到相同的错误.经过对SO的进一步研究后,我发现这只是一个错误,不会以任何方式影响应用程序.
另见“Creating an image format with an unknown type is an error Objective-C Xcode 8”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。