मैं छवि प्रपत्र QR Code
बनाने हूँ निम्नलिखित कोड का उपयोग करके असमर्थ इसे JPEG
या PNG
फ़ाइल में सहेजने के लिए। लेकिन जब मैं तो मेरे ऐप्लिकेशन क्रैश कर रहा हूँ:स्विफ्ट में UIImage को CIImage कन्वर्ट करने के लिए 3.0
@IBAction func btnSave(sender: AnyObject) {
// // Define the specific path, image name
let documentsDirectoryURL = try! NSFileManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
// create a name for your image
let fileURL = documentsDirectoryURL.URLByAppendingPathComponent("image.jpg")
if let image = imgviewQRcode.image // imgviewQRcode is UIImageView
{
if let path = fileURL?.path
{
if !NSFileManager.defaultManager().fileExistsAtPath(fileURL!.path!)
{
if UIImageJPEGRepresentation(image, 1.0)!.writeToFile(path, atomically: true)
{
print("file saved")
}
}//Checking existing file
}//Checking path
}//CHecking image
}
क्रैश प्वाइंट
UIImageJPEGRepresentation(image, 1.0)!.writeToFile(path, atomically: true)
कारण
fatal error: unexpectedly found nil while unwrapping an Optional value
डीबग टेस्ट:
@Shenona मैं इस विधि – Dalvik
इस विधि में क्या पास करना चाहिए CIImage की आवश्यकता है। इस पोस्ट के मुताबिक आपको सीआईएममेज को यूआईएममेज में बदलने में परेशानी हो रही है। इस विधि में पैरामीटर है जिसके लिए सीआईएममेज की आवश्यकता है और यूआईएममेज लौटाता है। – Shemona