图像I / O错误:“ addImageFromSource:2179:源的图像0为零”

时间:2019-07-05 10:43:56

标签: ios swift metadata dng

我正在尝试使用以下功能从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等)执行相同的过程,但没有一个出现此问题。如果有人可以帮助我,我将不胜感激。

0 个答案:

没有答案