使用 PHImageManager 时,PHAsset 为 UIImage 返回 nil 值
PHAsset is returning a nil value for the UIImage when using PHImageManager
知道为什么在添加 requestImageOption 设置后 return 对于 'thisImage' 为零吗?如果 options 设置为 nil thisAsset returns 一个值,但它是一个低分辨率图像,绝对不是原始高分辨率。我正在尝试 return 来自 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
//....
}
知道为什么在添加 requestImageOption 设置后 return 对于 'thisImage' 为零吗?如果 options 设置为 nil thisAsset returns 一个值,但它是一个低分辨率图像,绝对不是原始高分辨率。我正在尝试 return 来自 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
//....
}