title: How to use Core Image APIs to blur a image looks just like the `UIVisualView` effect?
body: <p>The first image below is the original image.<br>
  The second image is a blurred image implemented using Core Image API.<br>
  The third image is a blurred image implemented using <code>UIVisualView</code>. </p>
  
  <p>It's obvious that the Core Image blurred the image and shrunk it. The bigger radius resulted in a wider white border.  </p>
  
  <p><strong>Question:</strong> How to use core image make a visual effect just like the <code>UIVisualView</code> effect.</p>
  
  <p>At least, how to use Core Image to blur an image without the white border.  </p>
  
  <pre><code>func blur(image: UIImage, withRadius radius: Float) -&gt; UIImage {
      let context = CIContext(options: nil)
      let image = CIImage(image: image)
  
      let filter = CIFilter(name: "CIGaussianBlur")
      filter?.setValue(image, forKey: kCIInputImageKey)
      filter?.setValue(radius, forKey: "inputRadius")
      let result = filter?.outputImage
      return UIImage(cgImage: context.createCGImage(result!, from: (result?.extent)!)!)
  }
  </code></pre>
  
  <p>The third image is </p>
  
  <pre><code>func addVisualEffectView() {
      let effectView = UIVisualEffectView(effect: UIBlurEffect(style:.light))
      effectView.frame = originalImageView.bounds // originalImageView is the ImageView represents the original image
      originalImageView.addSubview(effectView)
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1M4Vm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1M4Vm.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/nDxTg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nDxTg.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/hjXol.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hjXol.png" alt="enter image description here"></a></p>