【发布时间】:2018-02-16 22:02:49
【问题描述】:
我使用了一个滑块来为我的图像添加模糊效果。我正在使用以下代码:
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
问题是每当滑块的值增加时,就会出现模糊效果,但是当我减小滑块的值时,它不会消除模糊效果。
【问题讨论】:
-
请显示更多代码! (1) 你的滑块是如何连接的? (2) 你的过滤器代码很好,但是,如何执行?这两件事都很重要,因为它们可能会影响
beginImage和processImage。 (希望你也使用GLKView。) -
@IBAction func slider(_ sender: UISlider) { DispatchQueue.main.async { self.colorControl.brightness(sender.value) self.imgImage.image = self.colorControl.outputUIImage() } -
我已使用此代码连接滑块,其事件发生在 Value Changed 上。 ,我没用过GLKView @dfd