14

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?

Samurai Jack
  • 2,985
  • 8
  • 35
  • 58
Dan Moldovan
  • 3,576
  • 2
  • 13
  • 24

2 Answers2

20

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

  }
bpolat
  • 3,879
  • 20
  • 26
  • 2
    You can also use [__GPUImage__](https://github.com/BradLarson/GPUImage) to do many image filters too. _GPUImage_ is sometimes claimed to be faster than _Core Image_. But if you don't do extensive blurring (like animated blurring), I think _Core Image_ is the way to go :D – yusuke024 Nov 20 '14 at 17:49
  • 1
    This is the way to go; it's a true Gaussian blur convolution. Keep in mind, though, that it's a little slow on iOS! – matt Nov 20 '14 at 17:50
  • @SikhapolSaijit Good point, thanks for reminding us of GPUImage. – matt Nov 20 '14 at 17:51
  • 8
    Warning - this takes a few seconds to run. Definitely not practical if you need the blur on demand. – thedayturns Apr 28 '15 at 19:44
5

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.

Judson Douglas
  • 331
  • 1
  • 5