当前位置 : 主页 > 手机开发 > ios >

iOS实现背景高斯模糊效果

来源:互联网 收集:自由互联 发布时间:2021-05-10
废话不多说,实现简单的高斯模糊的效果代码: UIView *bgview= [[UIViewalloc]initWithFrame:self.view.frame];// bgview.backgroundColor = [UIColor blackColor];// bgview.alpha = 0.9; bgview.tag =10086; [self.viewaddSubview:bgv

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

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

网友评论