gpt4 book ai didi

swift - UIImagePickerControllerDelegate 错误

转载 作者:行者123 更新时间:2023-11-30 12:49:28 25 4
gpt4 key购买 nike

所以我有这段代码可以获取我的画廊中的照片或使用相机更改 UIImage。

@IBAction func tappedCamera() {
print("tapped camera")

let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet)

let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: {
(alert: UIAlertAction!) -> Void in

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
self.picker.sourceType = UIImagePickerControllerSourceType.camera;
self.picker.allowsEditing = true
self.present(self.picker, animated: true, completion: nil)
}

})
let galleryAction = UIAlertAction(title: "Gallery", style: .default, handler: {
(alert: UIAlertAction!) -> Void in

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
self.picker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
self.picker.allowsEditing = true
self.present(self.picker, animated: true, completion: nil)
}


})
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
//do none
})


optionMenu.addAction(cameraAction)
optionMenu.addAction(galleryAction)
optionMenu.addAction(cancelAction)

self.present(optionMenu, animated: true, completion: nil)

}

但每当我尝试拍摄照片或从图库中选择图像时,我总是会收到此错误。

[Generic] Creating an image format with an unknown type is an error

最佳答案

我通过修复用户默认值解决了这个问题。因为代码中的某个地方我搞乱了图像,将它们转换为 base64 字符串,然后将其保存为用户默认值。

关于swift - UIImagePickerControllerDelegate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41182485/

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