全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

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

2 调用:

 Bitmap bitmap=null;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
      ImageUtil.updateBgToBlur(getActivity(), bitmap, slidingUpPanelLayout, R.drawable.bg_tageditor);
    } else {
      slidingUpPanelLayout.setBackgroundResource(R.drawable.bg_tageditor);
    }

二、高斯模糊布局:

项目需求: 现有一个紫色背景图片, 相册图片覆盖在背景图片 , 一个Framlayout 覆盖在这个含有相册图片的背景图中 ,实现模糊盖在上面的高斯模拟效果:

1 引用BlurView:

 compile 'com.eightbitlab:supportrenderscriptblur:1.0.0'
 compile 'com.eightbitlab:blurview:1.3.3'


 defaultConfig {
    renderscriptTargetApi 25 //must match target sdk and build tools, 23+
    renderscriptSupportModeEnabled true
 }

2 .调用:

final float radius = 20;

    final View decorView = getActivity().getWindow().getDecorView();
    //Activity's root View. Can also be root View of your layout (preferably)
    final ViewGroup rootView = (ViewGroup) decorView.findViewById(android.R.id.content);
    //set background, if your root layout doesn't have one
    final Drawable windowBackground = decorView.getBackground();


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      mBlurView.setupWith(rootView)
          .windowBackground(windowBackground)
          .blurAlgorithm(new RenderScriptBlur(getActivity()))
          .blurRadius(radius);
    }else {
      mBlurView.setupWith(rootView)
          .windowBackground(windowBackground)
          .blurAlgorithm(new SupportRenderScriptBlur(getActivity()))
          .blurRadius(radius);
    }

3 xml

 <eightbitlab.com.blurview.BlurView
   android:id="@+id/blurView"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:blurOverlayColor="@color/colorOverlay">

    <!--Any child View here, TabLayout for example-->

 </eightbitlab.com.blurview.BlurView>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# Android  # 高斯模糊  # Android实现图片的高斯模糊(两种方式)  # Android Picasso使用高斯模糊处理的示例代码  # Android 摄像头高斯模糊的示例代码  # Android项目实战之Glide 高斯模糊效果的实例代码  # 浅析Android高斯模糊实现方案  # Android仿微信通话背景的高斯模糊效果  # Android实现图片高斯模糊  # Android 三行代码实现高斯模糊效果  # 高斯  # 在这个  # 第一个  # 在上面  # 图中  # 大家多多  # Config  # getHeight  # RenderScript  # outBitmap  # Instantiate 


相关文章: 广州美橙建站如何快速搭建多端合一网站?  如何在腾讯云免费申请建站?  如何确保西部建站助手FTP传输的安全性?  建站之星后台管理如何实现高效配置?  c++ stringstream用法详解_c++字符串与数字转换利器  如何在云服务器上快速搭建个人网站?  如何在阿里云部署织梦网站?  浙江网站制作公司有哪些,浙江栢塑信息技术有限公司定制网站做的怎么样?  如何在阿里云完成域名注册与建站?  如何选择可靠的免备案建站服务器?  如何在腾讯云服务器上快速搭建个人网站?  如何通过VPS搭建网站快速盈利?  红河网站制作公司,红河事业单位身份证如何上传?  建站主机助手选型指南:2025年热门推荐与高效部署技巧  宝塔Windows建站如何避免显示默认IIS页面?  标准网站视频模板制作软件,现在有哪个网站的视频编辑素材最齐全的,背景音乐、音效等?  家族网站制作贴纸教程视频,用豆子做粘帖画怎么制作?  装修招标网站设计制作流程,装修招标流程?  代购小票制作网站有哪些,购物小票的简要说明?  关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)  自助网站制作软件,个人如何自助建网站?  建站上市公司网站建设方案与SEO优化服务定制指南  如何快速配置高效服务器建站软件?  已有域名和空间,如何快速搭建网站?  高防服务器租用指南:配置选择与快速部署攻略  儿童网站界面设计图片,中国少年儿童教育网站-怎么去注册?  音乐网站服务器如何优化API响应速度?  如何在服务器上配置二级域名建站?  南宁网站建设制作定制,南宁网站建设可以定制吗?  建站之星安装模板失败:服务器环境不兼容?  建站VPS选购需注意哪些关键参数?  如何在VPS电脑上快速搭建网站?  建站主机无法访问?如何排查域名与服务器问题  如何快速重置建站主机并恢复默认配置?  小捣蛋自助建站系统:数据分析与安全设置双核驱动网站优化  广东专业制作网站有哪些,广东省能源集团有限公司官网?  设计网站制作公司有哪些,制作网页教程?  高性能网站服务器部署指南:稳定运行与安全配置优化方案  建站之星如何实现网站加密操作?  如何在万网ECS上快速搭建专属网站?  常州自助建站工具推荐:低成本搭建与模板选择技巧  如何优化Golang Web性能_Golang HTTP服务器性能提升方法  定制建站是什么?如何实现个性化需求?  最好的网站制作公司,网购哪个网站口碑最好,推荐几个?谢谢?  如何快速生成专业多端适配建站电话?  已有域名如何免费搭建网站?  成都网站制作价格表,现在成都广电的单独网络宽带有多少的,资费是什么情况呢?  攀枝花网站建设,攀枝花营业执照网上怎么年审?  香港服务器选型指南:免备案配置与高效建站方案解析  免费制作统计图的网站有哪些,如何看待现如今年轻人买房难的情况? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。