0

I have a basic camera app working, but I would like to merge an image onto the image that was just captured. I would like to do this prior to saving it to the photo library. The function I have for saving the captured image data is this:

func saveToPhotoLibrary(_ photoData: Data) {
    
    PHPhotoLibrary.requestAuthorization { status in
        if status == .authorized {
            PHPhotoLibrary.shared().performChanges({
                let options = PHAssetResourceCreationOptions()
                let creationRequest = PHAssetCreationRequest.forAsset()
                options.uniformTypeIdentifier = self.requestedPhotoSettings.processedFileType.map { $0.rawValue } // self.requestedPhotoSettings: AVCapturePhotoSettings
                creationRequest.addResource(with: .photo, data: photoData, options: options)
                
                
            }, completionHandler: { _, error in
                if let error = error {
                    print("Error occurred while saving photo to photo library: \(error)")
                }
                
                DispatchQueue.main.async {
                    self.completionHandler(self)
                }
            }
            )
        } else {
            DispatchQueue.main.async {
                self.completionHandler(self)
            }
        }
    }
}

If I had an image at this point, I could draw an image onto an image and save that merged file (see this post), but I don't know how to do it with data, and I would prefer not to convert the data back and forth if I can help it. Any help would be appreciated.

Yrb
  • 8,103
  • 2
  • 14
  • 44

0 Answers0