gpt4 book ai didi

ios - 使用 PHImageManager 时,PHAsset 为 UIImage 返回 nil 值

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

知道为什么在添加 requestImageOption 设置后会为 'thisImage' 返回 nil 吗?如果 options 设置为 nil thisAsset 返回一个值,但它是一个低分辨率图像,绝对不是原始的高分辨率。我正在尝试从 PHAsset (thisAsset) 返回原始图像

    if let thisAsset:PHAsset = info[UIImagePickerController.InfoKey.phAsset] as? PHAsset {
arrImageIdentifiers.append(thisAsset.localIdentifier)

let manager = PHImageManager.default()
let requestImageOption = PHImageRequestOptions()
requestImageOption.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat

manager.requestImage(for: thisAsset, targetSize: PHImageManagerMaximumSize, contentMode: PHImageContentMode.default, options: requestImageOption, resultHandler: {(thisImage, _) in

Object.tempImage = thisImage

print("Picture metadata: \(thisAsset)")
let creationDate = thisAsset.creationDate

PhotoMeta.createDate = creationDate

})
//Get a reference to the camera view controller and call the savePhoto method
let cameraVC = self.selectedViewController as? CameraViewController

if let cameraVC = cameraVC {
cameraVC.savePhoto(image: Object.tempImage!)
}
}

最佳答案

将 requestOptions 的 isSynchronus 设置为 true 以解决您的问题:

    let requestImageOption = PHImageRequestOptions()
requestImageOption.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat
requestImageOption.isSynchronous = true

manager.requestImage(for: thisAsset, targetSize: PHImageManagerMaximumSize, contentMode: PHImageContentMode.default, options: requestImageOption, resultHandler: {(thisImage, _) in

//....
}

关于ios - 使用 PHImageManager 时,PHAsset 为 UIImage 返回 nil 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58456055/

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