iOS iOS下高斯模糊效果的實現

2021-07-14 13:48:29 字數 2222 閱讀 8086

其實有很多種實現方式,但是沒必要了解那麼多,簡單實用就行,選取一種效能相對來說比較好的方式

效果圖如下(高斯0.1):

**:

需要匯入

方法**:

#pragma mark - 高斯

- (uiimage *)blurryimage:(uiimage *)image withblurlevel:(cgfloat)blur

int boxsize = (int)(blur * 100);

boxsize = boxsize - (boxsize % 2) + 1;

cgimageref img = image.cgimage;

vimage_buffer inbuffer, outbuffer;

vimage_error error;

void *pixelbuffer;

cgdataproviderref inprovider = cgimagegetdataprovider(img);

cfdataref inbitmapdata = cgdataprovidercopydata(inprovider);

inbuffer.width = cgimagegetwidth(img);

inbuffer.height = cgimagegetheight(img);

inbuffer.rowbytes = cgimagegetbytesperrow(img);

inbuffer.data = (void*)cfdatagetbyteptr(inbitmapdata);

pixelbuffer = malloc(cgimagegetbytesperrow(img) *

cgimagegetheight(img));

if(pixelbuffer == null)

nslog(@"no pixelbuffer");

outbuffer.data = pixelbuffer;

outbuffer.width = cgimagegetwidth(img);

outbuffer.height = cgimagegetheight(img);

outbuffer.rowbytes = cgimagegetbytesperrow(img);

error = vimageboxconvolve_argb8888(&inbuffer,

&outbuffer,

null,

0,0,

boxsize,

boxsize,

null,

kvimageedgeextend);

if (error)

cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();

cgcontextref ctx = cgbitmapcontextcreate(

outbuffer.data,

outbuffer.width,

outbuffer.height,

8,outbuffer.rowbytes,

colorspace,

kcgimagealphanoneskiplast);

cgimageref imageref = cgbitmapcontextcreateimage (ctx);

uiimage *returnimage = [uiimage imagewithcgimage:imageref];

//clean up

cgcontextrelease(ctx);

cgcolorspacerelease(colorspace);

free(pixelbuffer);

cfrelease(inbitmapdata);

cgcolorspacerelease(colorspace);

cgimagerelease(imageref);

return returnimage;

}

Unity Shader 螢幕後效果 高斯模糊

高斯模糊是影象模糊處理中非常經典和常見的一種演算法,也是bloom螢幕效果的基礎。實現高斯模糊同樣用到了卷積的概念,關於卷積的概念和原理詳見我的另一篇部落格 通過高斯方程計算出的卷積核稱為高斯核,乙個5 5的高斯核對它進行權重歸一化如下 0.0030 0.0133 0.0219 0.0133 0.0...

蘋果導航條的高斯模糊效果(css)

今天接到乙個需求,實現乙個高斯模糊半透明的效果,以前沒有寫過這種效果,今天實現了,做乙個記錄 這個是給出的設計稿 可以看到,在免費預約門店的位置,滑動下來的文案,是乙個毛玻璃效果,底部的綠色是固定的 底部容器 btn bottom 其實這樣子就能實現毛玻璃的效果了,最主要的 還是在backdrop ...

高斯模糊的實現

今天設計提出來乙個需求,第一耳聽到時,我就蒙逼了。她說 這個頭像的背景你就用使用者頭像的圖示高斯模糊100 黑色的蒙層30 的不透明 後來經過我的不懈努力,在網上找到了完美的解決方案,驚奇的發現,所謂高大上的高斯模糊又稱為 毛玻璃效果 說毛玻璃效果就很easy了,網上一搜一大把的實現方式,結果都是使...