我遇到了以下错误代码:Creating an image format with an unknown type is an error
。我已经看到了几个与此有关的线程,但是似乎没有一个可以解决我的问题。我做错了什么是我的代码
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
let data = UIImagePNGRepresentation(image)
} else{
print("Something went wrong")
}
}
最佳答案
这可能是因为您没有打开可选的包装。
尝试更改此行:
let data = UIImagePNGRepresentation(image)
收件人:
let data = UIImagePNGRepresentation(image!)
希望对您有所帮助。
关于swift - ImagePickerController 在设备和模拟器上返回 "image format with an unknown type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41444684/