I have a portrait image with depth data with it and after some processing, I want to save a copy of it to a user photo album with depth data preserved (UIImage
not an option in this case). For this task, I am using the function writeJPEGRepresentation()
which seems to successfully save the modified image with the depth info to somewhere; however, it does not show up on the photo album.
In order it to appear on the photo album, I when try performChanges()
function of PHPhotoLibrary
,
this time it appeared on the album, but not the modified but the original one!?
Any help highly appreciated. Thanks.
Here is the code:
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")
}
}