淺析Android高斯模糊實(shí)現(xiàn)方案
1、使用Glide
Glide.with(this) .load(service.getImageUri()) .dontAnimate() .error(R.drawable.error_img) // 設(shè)置高斯模糊 .bitmapTransform(new BlurTransformation(this, 14, 3)) .into(imageview);
適用場(chǎng)景:動(dòng)態(tài)配置的背景圖片
2、對(duì)圖片高斯模糊,需要先將圖片轉(zhuǎn)成bitmap對(duì)象
mport android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; import android.os.Build; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RenderScript; import android.renderscript.ScriptIntrinsicBlur; public class BlurBitmapUtil { // 圖片縮放比例(即模糊度) private static final float BITMAP_SCALE = 0.4f; /** * @param context 上下文對(duì)象 * @param image 需要模糊的圖片 * @return 模糊處理后的Bitmap */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap blurBitmap(Context context, Bitmap image, float blurRadius) { // 計(jì)算圖片縮小后的長(zhǎng)寬 int width = Math.round(image.getWidth() * BITMAP_SCALE); int height = Math.round(image.getHeight() * BITMAP_SCALE); // 將縮小后的圖片做為預(yù)渲染的圖片 Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); // 創(chuàng)建一張渲染后的輸出圖片 Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); // 創(chuàng)建RenderScript內(nèi)核對(duì)象 RenderScript rs = RenderScript.create(context); // 創(chuàng)建一個(gè)模糊效果的RenderScript的工具對(duì)象 ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); // 由于RenderScript并沒(méi)有使用VM來(lái)分配內(nèi)存,所以需要使用Allocation類來(lái)創(chuàng)建和分配內(nèi)存空間 // 創(chuàng)建Allocation對(duì)象的時(shí)候其實(shí)內(nèi)存是空的,需要使用copyTo()將數(shù)據(jù)填充進(jìn)去 Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); // 設(shè)置渲染的模糊程度, 25f是最大模糊度 blurScript.setRadius(blurRadius); // 設(shè)置blurScript對(duì)象的輸入內(nèi)存 blurScript.setInput(tmpIn); // 將輸出數(shù)據(jù)保存到輸出內(nèi)存中 blurScript.forEach(tmpOut); // 將數(shù)據(jù)填充到Allocation中 tmpOut.copyTo(outputBitmap); return outputBitmap; } }
不推薦:使用bitmap,頻繁操作的話比較耗性能。
3、使用高斯模糊遮罩,可以對(duì)指定區(qū)域進(jìn)行模糊,不需要處理單張圖片(推薦?。。?/strong>
推薦一個(gè)github上的項(xiàng)目,親測(cè)有效。https://github.com/mmin18/RealtimeBlurView
<com.github.mmin18.widget.RealtimeBlurView android:id="@+id/blurview" android:layout_width="match_parent" android:layout_height="210dp" android:visibility="gone" app:realtimeBlurRadius="5dp" app:realtimeOverlayColor="#00000000" />
app:realtimeOverlayColor="#00000000",這里設(shè)置成透明色,效果就如同直接對(duì)圖片進(jìn)行高斯模糊。
總結(jié)
以上所述是小編給大家介紹的Android高斯模糊實(shí)現(xiàn)方案,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)我們網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
上一篇:Android實(shí)現(xiàn)3D層疊式卡片圖片展示
欄 目:Android
下一篇:使用Android WebSocket實(shí)現(xiàn)即時(shí)通訊功能
本文標(biāo)題:淺析Android高斯模糊實(shí)現(xiàn)方案
本文地址:http://mengdiqiu.com.cn/a1/Android/9125.html
您可能感興趣的文章
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)登錄
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10Emoji表情在Android JNI中的兼容性問(wèn)題詳解
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10android開發(fā)環(huán)境中SDK文件夾下的所需內(nèi)容詳解
- 01-10android異步消息機(jī)制 源碼層面徹底解析(1)


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10如何給Flutter界面切換實(shí)現(xiàn)點(diǎn)特效
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10Emoji表情在Android JNI中的兼容性問(wèn)題詳
隨機(jī)閱讀
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什