PhotoKit을 사용하여 사진을 편집하고 원본 사진의 메타 데이터를 보존해야합니다. 그렇게하려면 메타 데이터를 저장 한 다음 options
매개 변수 CGImageDestinationAddImage
에 제공하십시오. 마무리하고 디스크에 성공적으로 쓸 수 있지만 performChanges
을 호출하여 자산 편집을 커밋하면 실패합니다. options
에 nil
을 입력하면 성공합니다. 여기서 뭐가 잘못 됐어?이미지에 메타 데이터를 적용하면 performChanges 요청이 실패합니다.
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.)
는
나는 동일한 오류로 실행 한 ... 여기에 답하고있다. 사과에 열린 버그가 있습니까? – Glavid
@ 그래 비드 예, 그걸 들었습니다. 자신의 보고서를 작성하고 아무 것도 들리지 않으면 다시보고하십시오. – Joey
을 사용할 수 있습니다. Thanks – Glavid