Can you save an edited RAW .dng file on iOS?

前端 未结 4 1062
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 07:34

I want to build an iOS 10 app that lets you shoot a RAW (.dng) image, edit it, and then saved the edited .dng file to the camera roll. By combining

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 08:13

    This answer comes late, but it may help others with the problem. This is how I saved a raw photo to the camera roll as a .dng file.

    Just to note, I captured the photo using the camera with AVFoundation.

     import Photos
     import AVFoundation 
    
     //reading in the photo data in as a data object
     let photoData = AVCapturePhotoOutput.dngPhotoDataRepresentation(forRawSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer)
    
     // put it into a temporary file
     let temporaryDNGFileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("temp.dng")!     
     try! photoData?.write(to: temporaryDNGFileURL)
    
     // get access to photo library
     PHPhotoLibrary.requestAuthorization { status in
                if status == .authorized {
    
                    // Perform changes to the library
                    PHPhotoLibrary.shared().performChanges({
    
                        let options = PHAssetResourceCreationOptions()
                        options.shouldMoveFile = true
    
                        //Write Raw:
                        PHAssetCreationRequest.forAsset().addResource(with: .photo, fileURL: temporaryDNGFileURL, options: options)
    
                        }, completionHandler: { success, error in
                            if let error = error { print(error) }
                    })
    
                }
                else { print("cant access photo album") }
    }
    

    Hope it helps.

提交回复
热议问题