Is it possible to save AVDepthData as a PNG or JPEG?

Hey,


I am trying to save the depth data map which I extracted from the fileDataRepresentation() as a PNG or JPEG but it doesnt seem to work.

This is the code:


func photoOutput(_ output: AVCapturePhotoOutput,
                 didFinishProcessingPhoto photo: AVCapturePhoto,
                 error: Error?) {
        
        if let imageData = photo.fileDataRepresentation() {
            // get UIimage from image data
            image = UIImage(data: imageData)
            
            // read depth data from image
            var depthData = photo.depthData
            self.depthDataMap = depthData?.depthDataMap
            
            var ciImage = CIImage(cvPixelBuffer: self.depthDataMap!)
            ciImage = ciImage.oriented(forExifOrientation: 6)
            depthDataImage = UIImage(ciImage: ciImage)
            
            UIImageWriteToSavedPhotosAlbum(depthDataImage!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
            
            self.performSegue(withIdentifier: "viewImage", sender: self)
        }
    }