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;    }}

更多相关文章

  1. Android中MAC地址获取代码
  2. Android(Java):Android jni源代码
  3. Android 代码获取手机屏幕分辨率的代码
  4. Android实用代码片段(二)
  5. android典型代码系列(二十六)------App widget的使用
  6. android:inputType的XML与Java代码对应关系
  7. Android打开WIFI或者移动网络的代码实现

随机推荐

  1. [译]Android 安全概述之简介
  2. Android Hybrid开发入门:原生Android与JS
  3. andriod 源码树
  4. Android(安卓)手机的版本号 和 API 号码
  5. unity打包android全流程
  6. camera V4L2 FIMC
  7. 如何在Android中使用编译好的.so库【转ht
  8. Android初步-HelloWorld
  9. Android(安卓)Handler类
  10. Android 屏幕实现水龙头事件