編輯:關於Android編程
public static Bitmap blurBitmap(Bitmap bitmap, Context context) {
// 用需要創建高斯模糊bitmap創建一個空的bitmap
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
// 初始化Renderscript,這個類提供了RenderScript context,在創建其他RS類之前必須要先創建這個類,他控制RenderScript的初始化,資源管理,釋放
RenderScript rs = RenderScript.create(context);
// 創建高斯模糊對象
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
// 創建Allocations,此類是將數據傳遞給RenderScript內核的主要方法,並制定一個後備類型存儲給定類型
Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
// 設定模糊度
blurScript.setRadius(25.f);
// Perform the Renderscript
blurScript.setInput(allIn);
blurScript.forEach(allOut);
// Copy the final bitmap created by the out Allocation to the outBitmap
allOut.copyTo(outBitmap);
// recycle the original bitmap
bitmap.recycle();
// After finishing everything, we destroy the Renderscript.
rs.destroy();
return outBitmap;
}
然後是調用部分
public static Bitmap getBlurBitmap(View rootView, Context context) {
try {
if (rootView == null || context == null) {
return null;
}
rootView.setDrawingCacheEnabled(true);
Bitmap drawingCache = rootView.getDrawingCache();
Bitmap bgBitmap = Bitmap.createBitmap(drawingCache);
return BitmapUtil.blurBitmap(bgBitmap, context);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
這樣就可以就實現了高斯模糊效果,再將模糊效果顯示在界面上就可以了。
Android第三方微信支付教程
做了微信支付,下載了Demo,發現和之前有所改動,v3.0的版本,也許有的朋友還在摸索,這裡我已經成功支付,話不多說,直接進入主題:一、首先要在微信開發平台注冊賬號,新增
Android應用程序內存洩漏介紹
Android應用程序內存洩漏介紹內存洩漏和內存溢出的區別內存溢出(out of memory)是指程序在申請內存時,沒有足夠的內存空間供其使用,出現out of mem
Android應用開發:網絡工具——Volley(一)
引言 網絡一直是我個人的盲點,前一陣子抽出時間學習了一下Volley網絡工具的使用方法,也透過源碼進行了進一步的學習,有一些心得想分享出來。在Android
Android百度地圖應用之基本地圖功能實現
一、簡介 1、地圖 地圖展示:普通地圖(2D,3D)、衛星圖和實時交通圖。 地圖操作:可通過接口或手勢控制來實現地圖的點擊、雙擊、長按、縮放