欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS实现背景高斯模糊效果

程序员文章站 2023-12-21 20:59:34
废话不多说,实现简单的高斯模糊的效果代码: uiview *bgview= [[uiviewalloc]initwithframe:self.view.fra...

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

  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实现背景高斯模糊效果,希望对大家有所帮助

上一篇:

下一篇: