I am 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 using CIFIlter (imageData: options :), filter.outputImage is zero. Here is my code:
Image capture:
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) {
FileManager.default.createFile(atPath: rawFilePath, contents: data, attributes: nil)
}
}
The file is saved as expected, and I can easily open it in a light room.
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 zero, although the filter seems to be initialized. According to Apple, this can happen if the raw file format is in an unsupported format, but I donβt see how this applies to my case.
So: what do I need to do to get CIImagefrom a DNG file?