将元数据应用于图像会导致performChanges请求失败 [英] Applying metadata to image causes performChanges request to fail
问题描述
我正在使用PhotoKit编辑照片,我需要保留原始照片中的元数据。为此,我保存元数据,然后将其提供给 CGImageDestinationAddImage
中的选项
参数。我能够最终确定它并将其成功写入磁盘,但是当我调用 performChanges
来提交资产编辑时,它会失败。如果我为选项
提供 nil
,它将成功。这里出了什么问题?
I am using PhotoKit to edit photos and I need to preserve the metadata from the original photo. To do so I save the metadata then provide it to the options
parameter in CGImageDestinationAddImage
. I am able to finalize it and write it to disk successfully, but when I call performChanges
to commit the asset edit, it fails. If I instead provide nil
for options
it will succeed. What is going wrong here?
asset.requestContentEditingInputWithOptions(options) { (input: PHContentEditingInput!, _) -> Void in
//get full image
let url = input.fullSizeImageURL
let inputImage = CIImage(contentsOfURL: url)
//get orginal photo's metadata
let originalImageData = NSData(contentsOfURL: url)!
let imageSource = CGImageSourceCreateWithData(originalImageData, nil)
let metadata: CFDictionaryRef = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)
println(metadata) //prints all the metadata, yay!
//do some processing on original photo here and create an output CIImage...
//save to disk
let dataRef = CFDataCreateMutable(nil, 0)
let destination = CGImageDestinationCreateWithData(dataRef, CGImageSourceGetType(imageSource), 1, nil)
let eaglContext = EAGLContext(API: .OpenGLES2)
let ciContext = CIContext(EAGLContext: eaglContext)
let cgImage = ContextStruct.ciContext!.createCGImage(outputPhoto, fromRect: outputPhoto.extent())
CGImageDestinationAddImage(destination, cgImage, metadata) //metadata is problematic - replacing with nil causes it to work
if CGImageDestinationFinalize(destination) {
let contentEditingOutput = PHContentEditingOutput(contentEditingInput: input)
contentEditingOutput.adjustmentData = "something"
let imageData: NSData = dataRef
let success = imageData.writeToURL(contentEditingOutput.renderedContentURL, options: .AtomicWrite, error: _)
if success {
PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in
let request = PHAssetChangeRequest(forAsset: asset)
request.contentEditingOutput = contentEditingOutput
}, completionHandler: { (success: Bool, error: NSError!) -> Void in
if success == false { println('failed to commit image edit: \(error)') } //fails unless metadata is replaced with nil above
})
}
}
})
错误是:错误域= NSCocoaErrorDomain代码= -1操作无法完成。(可可错误-1。)
推荐答案
我有完全相同的问题,我已经提交了雷达rdar:// 21057247.我尝试使用TSI记录案例,但我被告知要提交雷达。
I have exactly the same problem, and I have filed a radar rdar://21057247. I try to log a case using TSI but I have been told to file a radar instead.
这篇关于将元数据应用于图像会导致performChanges请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!