gpt4 book ai didi

ios - Swift 4.2 无法将类型 '(UIImagePickerController.InfoKey).Type' 的值转换为预期的参数类型 'UIImagePickerController.InfoKey'

转载 作者:IT王子 更新时间:2023-10-29 05:22:54 25 4
gpt4 key购买 nike

我的以下代码在 swift 4 上运行良好,但在升级到 swift 4.2 后出现此错误,我浪费了 3 个小时搜索问题所在但失败了。如果有人能指导我如何解决这个问题,请多多指教。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

if postType == 2 {
let image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey)] as! UIImage
mediaType.image = image
} else {
videoURL = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.mediaURL)] as? URL
do {
let asset = AVURLAsset(url: videoURL!, options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImage(at: CMTime.init(value: 0, timescale: 1), actualTime: nil)
let thumbnail = UIImage(cgImage: cgImage)
self.mediaType.image = thumbnail
} catch {
print("*** Error generating thumbnail: \(error)")
}
}
picker.dismiss(animated: true, completion: nil)
}

最佳答案

你可以这样写...

if let image = info[.originalImage] as? UIImage {

print("image found")
//do something with an image

} else {
print("Not able to get an image")
}

编辑:

func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

//for original image
let originalImage = info[.originalImage]

//for edited image
let editedImage = info[.editedImage]

if #available(iOS 11.0, *) {
//gives URL of image picked by user
let imageURL = info[.imageURL]
}

//gives URL of media picked by user
let mediaURL = info[.mediaURL]
}

关于ios - Swift 4.2 无法将类型 '(UIImagePickerController.InfoKey).Type' 的值转换为预期的参数类型 'UIImagePickerController.InfoKey',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50928934/

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