Swift Gaussian Blur an image [closed]

2019-02-04 15:18发布

问题:

I've been developing an app for quite a while now and am soon to finish. I have been blurring some images using the UIImage+ImageEffects.h library, but now I want to switch to Gaussian blurring an UIImage

Is there any library or something similar that would allow me to gaussian blur an image in my app?

回答1:

I use following in my app.

 func applyBlurEffect(image: UIImage){
    var imageToBlur = CIImage(image: image)
    var blurfilter = CIFilter(name: "CIGaussianBlur")
    blurfilter.setValue(imageToBlur, forKey: "inputImage")
    var resultImage = blurfilter.valueForKey("outputImage") as CIImage
    var blurredImage = UIImage(CIImage: resultImage)
    self.blurImageView.image = blurredImage

  }


回答2:

I think UIBlurEffect is what you want, if you want to avoid the delay. The second half of this tutorial on Gaussian blur techniques in iOS 8 walks you through adding a UIBlurEffect to a UIImage.