我正在尝试使用以下功能从 DNG 图像中删除元数据:
fileprivate func removeMetadataFromPhotoData(data: Data) -> NSMutableData? {
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else {return nil}
guard var type = CGImageSourceGetType(source) else {return nil}
let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as Dictionary?
let dngDict = imageProperties?[kCGImagePropertyDNGDictionary]
var newDNGDict:NSMutableDictionary?
if let dict = dngDict {
newDNGDict = editDNGDict(originalDict: dict as! NSMutableDictionary)
}
let count = CGImageSourceGetCount(source)
let mutableData = NSMutableData(data: data)
guard let destination = CGImageDestinationCreateWithData(mutableData, type, count, nil) else {return nil}
let properties: NSMutableDictionary = [String(kCGImagePropertyGPSDictionary): kCFNull]
if let dngDictionary = newDNGDict {
properties[String(kCGImagePropertyDNGDictionary)] = dngDictionary
}
print("SOURCE: \(source)")
for i in 0..<count {
CGImageDestinationAddImageFromSource(destination, source, i, properties as CFDictionary)
}
guard CGImageDestinationFinalize(destination) else {return nil}
return mutableData
}
print 语句打印 的值source
,因此源不是 nil。但是,当执行下一行时,我收到以下错误:
addImageFromSource:2179: 源的图像 0 为零
finalize:2470:图像目标必须至少有一张图像
我对其他格式(JPG、PNG、TIFF 等)执行相同的过程,但它们都没有这个问题。如果有人可以帮助我,我将不胜感激。