无法从文件读取DNG

Joe*_*Doe 5 camera ios dng swift

我试图在上捕获图像iOS10,将其以原始格式存储,然后再处理。拍摄和保存图像不是问题,但是当我稍后尝试使用CIFIlter(imageData:options :)打开DNG文件时,filter.outputImage为nil。这是我的代码:

拍摄图像:

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)

    }

}
Run Code Online (Sandbox Code Playgroud)

该文件已按预期保存,我可以在lightroom中打开它而不会出现问题。

这是再次读取文件的代码:

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
Run Code Online (Sandbox Code Playgroud)

但是,即使过滤器似乎已初始化,输出图像也为零。根据Apple的说法,如果原始文件的格式具有不受支持的格式,则可能会发生这种情况,但是我不知道这将如何适用于我的情况。

所以:我需要怎么做才能CIImage从DNG文件中获取文件?