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