android 使用randerScript实现图片模糊效果
16lz
2022-01-26
1.build.gradle 配置:
android { defaultConfig { renderscriptTargetApi 19 renderscriptSupportModeEnabled true }}
2.使用如下代码:
public class BlurBuilder { private static final float BITMAP_SCALE = 0.2f; private static final float BLUR_RADIUS = 15f; public static Bitmap blur(Context context, Bitmap image) { int width = Math.round(image.getWidth() * BITMAP_SCALE); int height = Math.round(image.getHeight() * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); theIntrinsic.setRadius(BLUR_RADIUS); theIntrinsic.setInput(tmpIn); theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; }}
更多相关文章
- Android(安卓)获取屏幕分辨率
- Failed to install the following Android(安卓)SDK packages as
- android mvvm databinding在dialog中的使用
- Android(安卓)Studio AIDL进行IPC通信的使用步骤
- Android(安卓)AsyncTask 异步任务取消
- Android中MAC地址获取代码
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用