gpt4 book ai didi

ios - 将元数据应用于图像会导致 performChanges 请求失败

转载 作者:可可西里 更新时间:2023-11-01 05:44:01 24 4
gpt4 key购买 nike

我正在使用 PhotoKit 编辑照片,我需要保留原始照片的元数据。为此,我保存了元数据,然后将其提供给 CGImageDestinationAddImage 中的 options 参数。我能够完成它并将其成功写入磁盘,但是当我调用 performChanges 提交 Assets 编辑时,它失败了。如果我改为为 options 提供 nil,它将成功。这里出了什么问题?

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
})
}
}
})

错误是:Error Domain=NSCocoaErrorDomain Code=-1 "The operation couldn't be completed. (Cocoa error -1.)

最佳答案

似乎必须填充 PHContentEditingOutput 对象的 adjustementData 属性才能编辑照片。

关于ios - 将元数据应用于图像会导致 performChanges 请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28267435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com