资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Android实现图片转高斯模糊以及高斯模糊布局-创新互联

第一个为大家介绍图片如何转高斯模拟:

创新互联公司专注于于都网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供于都营销型网站建设,于都网站制作、于都网页设计、于都网站官网定制、小程序开发服务,打造于都网络公司原创品牌,更为您提供于都网站排名全网营销落地服务。

1.方法的实现:

public static void updateBgToBlur(Activity a, Bitmap bmpToBlur, View view, int resId) {
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;
    opt.inSampleSize = 8;
    opt.inJustDecodeBounds = false;
    Bitmap bmp = BitmapFactory.decodeResource(a.getResources(), resId, opt);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
      view.setBackground(null);
    } else {
      view.setBackgroundDrawable(null);
    }
    if (bmpToBlur != null && !bmpToBlur.isRecycled()) {
      bmpToBlur.recycle();
    }
    bmpToBlur = blurBitmap(a, bmp);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      view.setBackground(new BitmapDrawable(a.getResources(), bmpToBlur));
    } else {
      view.setBackgroundDrawable(new BitmapDrawable(a.getResources(), bmpToBlur));
    }
  }


  public static Bitmap blurBitmap(Context c, Bitmap bitmap) {

    //Let's create an empty bitmap with the same size of the bitmap we want to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_4444);

    //Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(c.getApplicationContext());

    //Create an Intrinsic Blur Script using the Renderscript
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);

    //Set the radius of the blur
    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;
  }


文章名称:Android实现图片转高斯模糊以及高斯模糊布局-创新互联
标题网址:http://cdkjz.cn/article/dsojhh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220