[I'm in the process of learning of Swift Development. Last time I've tried to add a blur for a picture of Ronald Reagan. First I found UIBlurEffect method, but it wasn't exactly what I expected. Then I tried to use CIFilter method. I walked through horrible way of implementing CIGaussianBlur, but eventually I made it! Then I looked into storyboard, and I found out that picture was scaled and marked with white bezels (as you can see on attached pic). What I did wrong? What should I do? Is there more simple way to add blur on a photo programmatically? I know there is a way to do that by third side apps like Adobe PS, but I want to have it in code. :)
import UIKit
@IBDesignable
class blurImageView: UIImageView {
override func awakeFromNib() {
super.awakeFromNib()
applyBlurEffect(image: image!)
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
applyBlurEffect(image: image!)
}
func applyBlurEffect(image: UIImage){
if self.image != nil {
let imageToBlur = CIImage(image: image)
let blurfilter = CIFilter(name: "CIGaussianBlur")!
blurfilter.setValue(imageToBlur, forKey: "inputImage")
let resultImage = blurfilter.value(forKey: "outputImage") as! CIImage
let blurredImage = UIImage(ciImage: resultImage)
self.image = blurredImage
}
}
}