在 Swift 中重置 CoreImage 过滤器

Reset CoreImage filter in Swift

我正在开发简单的 coreImage 过滤器项目 Swift.I 我正在尝试实现将过滤图像重置为原始图像的功能。我正在为 SepiaTone 滤镜使用以下代码,我正在尝试使用 CIColorControls 重置滤镜 filter.But 我越来越致命 crash.I 想知道是否有任何其他方法可以重置图像。

        @IBOutlet weak var originalImage: UIImageView!

        @IBAction func SepiaToneFilter(sender: AnyObject) {
        let mySepiaFilter = CIFilter(name: "CISepiaTone")
        mySepiaFilter!.setValue(CIImage(image: originalImage.image!), forKey: kCIInputImageKey)
        let myOutputImage : CIImage = mySepiaFilter!.outputImage!            
        originalImage.image = UIImage(CIImage: myOutputImage)
        }

        @IBAction func ResetFilter(sender: AnyObject) {

        let currentFilter = CIFilter(name: "CIColorControls") 
        let beginImage = CIImage(image: originalImage.image!)
        currentFilter!.setValue(beginImage, forKey: kCIInputImageKey
        let output = currentFilter!.outputImage 

        let cgimg = context.createCGImage(output!, fromRect: output!.extent)  **//CreateWrappedSurface() failed for a dataprovider-backed CGImageRef.fatal error: unexpectedly found nil while unwrapping an Optional value
     (lldb)** 

        let processedImage = UIImage(CGImage: cgimg)
        originalImage.image = processedImage
        } 

//取图过程

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

我不确定如何 运行 我的 ResetFilter(UIButton) 中的上述函数。

提前致谢

为什么不只保留对原始图像的引用?例如:

    @IBOutlet weak var originalImage: UIImageView!
    var userImage?:UIImage

    @IBAction func SepiaToneFilter(sender: AnyObject) {
        let mySepiaFilter = CIFilter(name: "CISepiaTone")
        if let image = self.userImage {
            mySepiaFilter!.setValue(CIImage(image: image), forKey: kCIInputImageKey)
            let myOutputImage : CIImage = mySepiaFilter!.outputImage!            
            originalImage.image = UIImage(CIImage: myOutputImage)
        }
    }

    @IBAction func ResetFilter(sender: AnyObject) {
        if let image = self.userImage {
            self.originalImage.image = image
        }

    } 


    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
            self.userImage = image
            originalImage.image = image
            self.dismissViewControllerAnimated(true, completion: nil);
    }