废话不多说,实现简单的高斯模糊的效果代码:
1
2
3
4
5
6
7
8
9
|
UIView *bgview= [[UIViewalloc]initWithFrame:self.view.frame]; // bgview.backgroundColor = [UIColor blackColor]; // bgview.alpha = 0.9; bgview.tag = 10086 ; [self.viewaddSubview:bgview]; UIBlurEffect *blur = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *effectview = [[UIVisualEffectViewalloc] initWithEffect:blur]; effectview.frame =self.view.frame; [bgview addSubview:effectview]; |
这写代码只是简单的实现高斯模糊。关于消除,把它remove就行了。
关于图片的高斯模糊,首先拿到图片:
1
2
3
4
5
6
7
8
9
10
11
12
|
CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@ "1.png" ]]; // create gaussian blur filter CIFilter *filter = [CIFilter filterWithName:@ "CIGaussianBlur" ]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:[NSNumber numberWithFloat: 10.0 ] forKey:@ "inputRadius" ]; // blur image CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]]; UIImage *image = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); self.mainImageView.image = image; |
以上所述是小编给大家介绍的iOS实现背景高斯模糊效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://blog.csdn.net/requestnslog/article/details/53609690