swift - ImagePickerController 在设备和模拟器上返回 "image format with an unknown type"

标签 swift

我遇到了以下错误代码: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/

相关文章:

ios - 在 UIViewController 类中,@IBOutlet self.tableView 为 nil

regex - Swift - 正则表达式匹配引号中的任何内容

ios - 让 XCUIElement 为自动化 UITest 执行 3D 触摸?

arrays - 最佳数据在索引/数据屏蔽处获取/设置 uint8

swift - 使用后重置 UIPickerview?

swift - 将字符串文本转换为变量名?

ios - 如何使带有白色字体的导航栏透明?

ios - Swift 中的 PFUser logInWithUsernameInBackground - 参数 'target' 调用缺少参数

ios - 使用 UIBezierPath 在 Swift 3.x 中画一条线

ios - 快速从 healthkit 中获取周、月和年格式的用户数据