Save Image with filter to Photo Library in Swift 3.0
<p>I'm using Core Image in Swift for editing photos and I have a problem when I save the photo. After applying a filter to the photo, it can not be saved. But without the filter, it can be saved. Any ideas how?</p>

<pre><code>import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var pickedImaged: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


@IBAction func camerabuttonaction(_ sender: UIButton) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
    let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)
    }
}


@IBAction func photolibraryaction(_ sender: UIButton) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)
    }
}


@IBAction func saveaction(_ sender: UIButton) {
UIImageWriteToSavedPhotosAlbum(pickedImaged.image!, nil, nil, nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]) {   
    pickedImaged.image = image
    self.dismiss(animated: true, completion: nil);     
}


@IBAction func addfilter(_ sender: UIButton) {

    let image = pickedImaged.image, cgimg = image?.cgImage
    let coreImage = CIImage(cgImage: cgimg!)      
    let filter = CIFilter(name: "CISepiaTone")
    filter?.setValue(coreImage, forKey: kCIInputImageKey)
    filter?.setValue(0.5, forKey: kCIInputIntensityKey)     
    let output = filter?.value(forKey: kCIOutputImageKey) as? CIImage
    let filteredImage = UIImage(ciImage: output!)
    pickedImaged.image = filteredImage       
}


}
</code></pre>