iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android实现图片转高斯模糊以及高斯模糊布局
  • 236
分享到

Android实现图片转高斯模糊以及高斯模糊布局

android高斯模糊roi 2023-05-30 22:05:41 236人浏览 八月长安
摘要

第一个为大家介绍图片如何转高斯模拟:方法的实现:public static void updateBgToBlur(Activity a, Bitmap bmpToBlur, View view, int resId) {

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

方法的实现:

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

--结束END--

本文标题: Android实现图片转高斯模糊以及高斯模糊布局

本文链接: https://www.lsjlt.com/news/221875.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作