Android 使用RenderScript 实现毛玻璃(模糊)
2017-12-05 16:24
197 查看
build.gradle 配置:
获取当前view 截图
工具截图获取毛玻璃图片:
得到的模糊图片即View的高斯模糊效果图。可以通过addView方法或者setImageBitmap方法等实现效果
defaultConfig { renderscriptTargetApi 19 renderscriptSupportModeEnabled true }
获取当前view 截图
public static Bitmap getViewBitmap(View view) { if(view.getWidth() == 0 || view.getHeight() == 0) return null; Bitmap b = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); view.draw(c); return b; }
工具截图获取毛玻璃图片:
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) { final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(bitmap); sentBitmap.recycle(); rs.destroy(); input.destroy(); output.destroy(); script.destroy(); return bitmap; }
得到的模糊图片即View的高斯模糊效果图。可以通过addView方法或者setImageBitmap方法等实现效果
相关文章推荐
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- android使用RenderScript模糊图片技术
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- Android学习------使用RenderScript ,ScriptIntrinsicBlur实现高斯模糊
- android 毛玻璃模糊效果背景实现
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- Android 实现图片模糊、高斯模糊、毛玻璃效果的三种方法
- 使用RenderScript来实现高斯模糊,兼容低版本
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- Android利用RenderScript对图片处理实现高斯模糊效果。
- Android 图片模糊、高斯模糊、毛玻璃的三种实现方法
- Android:用RenderScript实现模糊效果
- RenderScript----Android图片模糊效果的简单实现
- Android利用RenderScript实现毛玻璃模糊效果示例
- android使用 2D 方法实现倒影特效
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- 使用Android自带Gallery组件实现CoverFlow,源码+解析
- [Android]使用二维表格实现 TableLayout 跨行(转)