我正在尝试在 上捕获图像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)
}
}
该文件按预期保存,我可以在 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
然而,输出图像为零,即使过滤器似乎已初始化。根据 Apple 的说法,如果原始文件的格式具有不受支持的格式,则可能会发生这种情况,但我不知道这将如何适用于我的情况。
那么:我需要做什么才能CIImage
从 DNG 文件中获取一个?