gpt4 book ai didi

swift3 - Xcode 8 - 快速 3 : Creating an image format with an unknown type is an error

转载 作者:行者123 更新时间:2023-12-04 20:33:38 25 4
gpt4 key购买 nike

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

}

最佳答案

我没有将委托(delegate)添加为 ' 也遇到了同样的问题自我 ' 对于 UIImagePickerController。添加后,我能够从图库中获取选定的图像。但即使将委托(delegate)添加为 自我 并且能够访问图像(在 ImageView 上显示),我仍然遇到同样的错误。经过对 SO 的进一步研究,我知道这只是一个错误,不会以任何方式影响应用程序。

另见 "Creating an image format with an unknown type is an error Objective-C Xcode 8"

关于swift3 - Xcode 8 - 快速 3 : Creating an image format with an unknown type is an error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40347169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com