gpt4 book ai didi

swift - 上传图像到解析失败

转载 作者:行者123 更新时间:2023-11-30 12:04:31 24 4
gpt4 key购买 nike

我无法保存捕获的图像并使用 Parse 将其发送到我的 mongodb。我不确定我的错误与什么有关。我使用 imagePickerController 确实正确地捕获了图像。

这是我的代码:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("Did finish picking media. Image \(image)")


let imageData = UIImagePNGRepresentation(image)
let imageFile = PFFile(name:"image.png", data:imageData!)



let pohto_object = PFObject(className: "UserPhoto")
pohto_object["imageName"] = "My trip to Hawaii!"
pohto_object["imageFile"] = imageFile

pohto_object.saveInBackground() { (success, error) -> Void in
if error == nil {
print("Saved in server")
} else {
print("did not save because: \(error!)")
}
}
print ("the object is \(pohto_object)")




} else {
print("Did finish picking media. Image is nil")
}
dismiss(animated: true)
}

这是我在控制台中的输出:

Did finish picking media. Image <UIImage: 0x17468ac30> size {3024, 4032} orientation 3 scale 1.000000

libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

所以我的问题通过从 UIImagePNGRepresentation 更改为 UIImageJPEGRepresentation 得到解决,如 Leo 所示

关于swift - 上传图像到解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46820229/

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