I have used a slider for blur effect to my image. I am using the following code:
let currentFilter = CIFilter(name: "CIGaussianBlur")
let beginImage = CIImage(image: imgImage.image!)
currentFilter!.setValue(beginImage, forKey: kCIInputImageKey)
currentFilter!.setValue(sender.value, forKey: kCIInputRadiusKey)
let cropFilter = CIFilter(name: "CICrop")
cropFilter!.setValue(currentFilter!.outputImage, forKey: kCIInputImageKey)
cropFilter!.setValue(CIVector(cgRect: beginImage!.extent), forKey: "inputRectangle")
let output = cropFilter!.outputImage
let cgimg = context.createCGImage(output!, from: output!.extent)
let processedImage = UIImage(cgImage: cgimg!)
imgImage.image = processedImage
The issue is whenever the slider's value is incremented the blur effect appears but when I decrease the value of the slider then it will not removing the blur effect.
You can apply the filter into your original image instead of already filtered image. Try below code.
Output from Simulator:
Note: I recommend you to test the code in real device as Simulator performance is too slow on coreImage.
Make separate class which adds the blur effect: