Swift3 Xcode 8-swift 3:创建具有未知类型的图像格式时出错
使用UIImagePicker选择图像时出错:Swift3 Xcode 8-swift 3:创建具有未知类型的图像格式时出错,swift3,uiimagepickercontroller,ios10,xcode8.1,Swift3,Uiimagepickercontroller,Ios10,Xcode8.1,使用UIImagePicker选择图像时出错: [Generic] Creating an image format with an unknown type is an error 我使用的是Xcode 8.1和Swift 3。 我已经在网上搜索过了,但似乎没有什么能解决我的问题,请帮助 这是我的代码: class TabBarController: UITabBarController, UIImagePickerControllerDelegate, UINavigationContro
[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
}
}
}
}
}您能否将
info
参数的.debugDescription
发布到您的选取器代理中
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : Any]) {
print(info.debugDescription)
...
}
我遇到了同样的问题,没有为UIImagePickerController添加作为“self”的委托。添加后,我能够从gallery中获取所选图像。但是,即使将委托添加为self并能够访问图像(显示在ImageView上),我仍然会遇到相同的错误。经过对SO的进一步研究,我知道这只是一个bug,不会以任何方式影响应用程序
另请参见以下信息。debugDescription:[“UIImagePickerController中间类型”:public.image,“UIImagePickerController参考URL”:资产-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG,“UIImagePickerControllerOriginalImage”:尺寸{3000,2002}方向0比例1.000000],如果让图像=信息[UIImagePickerControllerEditedImage]为?UIImage{//保存图像}如果让image=info[UIImagePickerControllerOriginalImage]为?UIImage{//保存图像}其他{打印(“出错”)}可能重复的