6

I'm trying to capture an image on iOS10, store it in raw format and then process it later. Taking and saving the image is not a problem, but when I try to open the DNG file later with CIFIlter(imageData:options:), the filter.outputImage is nil. Here's my code:

Taking the image:

func capture(_ captureOutput: AVCapturePhotoOutput,
             didFinishProcessingRawPhotoSampleBuffer rawSampleBuffer: CMSampleBuffer?,
             previewPhotoSampleBuffer: CMSampleBuffer?,
             resolvedSettings: AVCaptureResolvedPhotoSettings,
             bracketSettings: AVCaptureBracketedStillImageSettings?,
             error: Error?) {


    if let rawSampleBuffer = rawSampleBuffer,
        let data = AVCapturePhotoOutput.dngPhotoDataRepresentation(forRawSampleBuffer: rawSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer) {

        // rawFilePath is a filename in my sandbox
        FileManager.default.createFile(atPath: rawFilePath, contents: data, attributes: nil)

    }

}

The file is saved as expected and I can open it in lightroom without problems.

This is the code to read the file again:

let imageData = try? Data(contentsOf: URL(fileURLWithPath: rawFilePath))

if imageData == nil {
    return nil
}

let filter = CIFilter(
     imageURL: URL(fileURLWithPath: filename),
     options: [String(kCGImageSourceTypeIdentifierHint): "com.adobe.raw-image"]
)

let ciImage: CIImage? = filter?.outputImage

However, the output image is nil, even though the filter seems to be initialized. According to Apple, this can happen if the format of the raw file has an unsupported format, but I don't see how that would apply to my case.

So: what do I need to do to get a CIImage from the DNG file?

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
Joern Doe
  • 61
  • 5

0 Answers0