如何更改UIImage中模糊的颜色?我需要一个黑色的模糊,我不知道该怎么做。我在Stackoverflow(Blur UIImage to achieve effect like passcode blur of the wallpaper with swift)中找到了另一个答案。这个答案是完美的,但模糊很轻,我需要它是黑色的。谁能帮我? PS:下面的代码是另一个问题的答案。
func applyBlurEffect(image: UIImage){
var imageToBlur = CIImage(image: image)
var blurfilter = CIFilter(name: "CIGaussianBlur")
blurfilter.setValue(5, forKey: kCIInputRadiusKey)
blurfilter.setValue(imageToBlur, forKey: "inputImage")
var resultImage = blurfilter.valueForKey("outputImage") as! CIImage
var blurredImage = UIImage(CIImage: resultImage)
var cropped:CIImage=resultImage.imageByCroppingToRect(CGRectMake(0, 0,imageToBlur.extent().size.width, imageToBlur.extent().size.height))
blurredImage = UIImage(CIImage: cropped)
self.backgroundImage.image = blurredImage
}
答案 0 :(得分:4)
let imageView = UIImageView(image: UIImage(named: "example"))
imageView.frame = view.bounds
imageView.contentMode = .ScaleToFill
view.addSubview(imageView)
let blurEffect = UIBlurEffect(style: .Dark)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.frame = imageView.bounds
view.addSubview(blurredEffectView)