android 使用randerScript实现图片模糊效果
16lz
2021-01-23
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中MAC地址获取代码
- Android(Java):Android jni源代码
- Android 代码获取手机屏幕分辨率的代码
- Android实用代码片段(二)
- android典型代码系列(二十六)------App widget的使用
- android:inputType的XML与Java代码对应关系
- Android打开WIFI或者移动网络的代码实现