2015-06-04 11 views
7

विफल रहता है मैं एक ऐप विकसित कर रहा हूं जो उपयोगकर्ताओं को फोटोकिट का उपयोग करके फोटो संपादित करने की अनुमति देता है। मैं पहले संपादित तस्वीर को एक जेपीईजी के रूप में डिस्क में सहेज रहा था। मैं जेपीईजी में परिवर्तित होने से बचना चाहता हूं और ऐसा करने के लिए संशोधनों को लागू करना चाहता हूं। यह कैमरे के साथ ली गई तस्वीरों के लिए बहुत अच्छा काम करता है, लेकिन यदि आप स्क्रीनशॉट को संपादित करने का प्रयास करते हैं, तो PHPhotoLibrary.sharedPhotoLibrary().performChanges ब्लॉक विफल हो जाएगा और The operation couldn’t be completed. (Cocoa error -1.) लॉग इन करेगा। मुझे यकीन नहीं है कि यह निष्पादन चेंज ब्लॉक को विफल क्यों कर रहा है, मैंने यहां क्या गलत किया है?स्क्रीनशॉट संपादित करने में असमर्थ, प्रदर्शन चेंज ब्लॉक

मैंने sample app available to download बनाया है जो समस्या का प्रदर्शन करता है, और मैंने नीचे प्रासंगिक कोड शामिल किया है। ऐप आपकी फोटो लाइब्रेरी में नवीनतम तस्वीर को संपादित करने का प्रयास करता है। यदि यह सफल होता है तो यह फ़ोटो को संपादित करने के लिए पहुंच के लिए संकेत देगा, अन्यथा कुछ भी नहीं होगा और आपको कंसोल लॉग दिखाई देगा। इस मुद्दे को पुन: उत्पन्न करने के लिए, स्क्रीनशॉट लें और फिर ऐप चलाएं।

वर्तमान कोड है कि स्क्रीनशॉट के साथ काम करता है:

let jpegData: NSData = outputPhoto.jpegRepresentationWithCompressionQuality(0.9) 

let contentEditingOutput = PHContentEditingOutput(contentEditingInput: self.input) 

var error: NSError? 
let success = jpegData.writeToURL(contentEditingOutput.renderedContentURL, options: NSDataWritingOptions.AtomicWrite, error: &error) 
if success { 
    return contentEditingOutput 
} else { 
    return nil 
} 

रिप्लेसमेंट कोड का कारण बनता है कि स्क्रीनशॉट विफल:

let url = self.input.fullSizeImageURL 
let orientation = self.input.fullSizeImageOrientation 
var inputImage = CIImage(contentsOfURL: url) 
inputImage = inputImage.imageByApplyingOrientation(orientation) 

let outputPhoto = createOutputImageFromInputImage(inputImage)! 

let originalImageData = NSData(contentsOfURL: self.input.fullSizeImageURL)! 
let imageSource = CGImageSourceCreateWithData(originalImageData, nil) 

let dataRef = CFDataCreateMutable(nil, 0) 
let destination = CGImageDestinationCreateWithData(dataRef, CGImageSourceGetType(imageSource), 1, nil) //getType automatically selects JPG, PNG, etc based on original format 

struct ContextStruct { 
    static var ciContext: CIContext? = nil 
} 
if ContextStruct.ciContext == nil { 
    let eaglContext = EAGLContext(API: .OpenGLES2) 
    ContextStruct.ciContext = CIContext(EAGLContext: eaglContext) 
} 

let cgImage = ContextStruct.ciContext!.createCGImage(outputPhoto, fromRect: outputPhoto.extent()) 

CGImageDestinationAddImage(destination, cgImage, nil) 

if CGImageDestinationFinalize(destination) { 
    let contentEditingOutput = PHContentEditingOutput(contentEditingInput: self.input) 

    var error: NSError? 
    let imageData: NSData = dataRef 
    let success = imageData.writeToURL(contentEditingOutput.renderedContentURL, options: .AtomicWrite, error: &error) 
    if success { 
      //it does succeed 
      return contentEditingOutput 
    } else { 
      return nil 
    } 
} 

उत्तर

0

समस्या तथ्य यह है कि समायोजित तस्वीरें हमेशा JPG फ़ाइलें के रूप में सहेजा जाता है के कारण होता है, और स्क्रीनशॉट वास्तव में पीएनजी फाइलें हैं।

यह जब तक मैं अपने नमूना परियोजना डिबगिंग गया था मेरे लिए हुआ है और PhotoEditor में देखा था, contentEditingOutput.renderedContentURL, एक JPG के लिए एक URL है, जबकि यदि आप CGImageSourceGetType(imageSource) का परिणाम की जांच यह स्पष्ट है यह एक PNG (रिटर्न एक PNG यूटीआई है : public.png)। यदि आपके छवि एक PNG है जो स्पष्ट रूप से काम नहीं करेगा -

तो मैं renderedContentURL जिसमें कहा गया है कि एक तस्वीर संपत्ति संपादन करते हैं, बदले हुए चित्र JPEG प्रारूप में लिखा है के लिए चला गया और documentation पढ़ें। इससे मुझे लगता है कि ऐप्पल पीएनजी फाइलों को संपादित करने का समर्थन नहीं करता है या आप नहीं चाहते हैं। जाओ आंकड़ा ..

+0

मैंने ऐप्पल के साथ एक बग लॉग किया है। यह बग आईओएस 9 और 10 में भी मौजूद है। स्पष्ट रूप से उनके लिए ठीक करने के लिए उच्च प्राथमिकता नहीं है। – jjxtra

संबंधित मुद्दे