首页 > 系统 > iOS > 正文

iOS实现背景高斯模糊效果

2020-07-26 03:02:14
字体:
来源:转载
供稿:网友

废话不多说,实现简单的高斯模糊的效果代码:

  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就行了。

关于图片的高斯模糊,首先拿到图片:

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实现背景高斯模糊效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表