【发布时间】:2019-12-18 13:07:09
【问题描述】:
我有一张带有深度数据的肖像图像,经过一些处理后,我想将其副本保存到保留深度数据的用户相册中(UIImage 在这种情况下不是一个选项)。对于这个任务,我正在使用函数writeJPEGRepresentation(),它似乎成功地将带有深度信息的修改后的图像保存到某个地方;但是,它不会显示在相册中。
为了出现在相册中,我在尝试PHPhotoLibrary的performChanges()功能时,
这次出现在专辑里的不是修改版而是原版!?
任何帮助高度赞赏。谢谢。
代码如下:
func saveWithDepth(image : CIImage) {
do {
let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
let depthdata = DepthData
let url = Url
try Context.writeJPEGRepresentation(of: image, to: url!, colorSpace: colorSpace!,
options: [CIImageRepresentationOption.avDepthData :depthdata!])
PHPhotoLibrary.shared().performChanges({
let options = PHAssetResourceCreationOptions()
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .alternatePhoto, fileURL: url!, options: options)
}, completionHandler: { success, error in
if !success {
print("AVCam couldn't save the movie to your photo library: \(String(describing: error))")
}
})
} catch {
print("failed")
}
}
【问题讨论】:
-
你解决过这个问题吗?
标签: ios swift photo core-image phphotolibrary