栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android RenderScript高斯模糊

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android RenderScript高斯模糊

看代码的时候,看到了其中有.rs结尾的文件,不是很明白,还有Renderscript类,看的一脸蒙蔽,不知所云,然后百度了一下,收货还真不少,这东西在图形处理这块用处挺大的。

今天先说说scriptIntrinsicBlur,这个类不需要定义rs文件,从这个Intrinsic单词可以看的出来,它是API17以后内置的类,专门用来处理图像的,让图片变模糊。

public static Bitmap blurBitmap(Bitmap bitmap, float radius, Context context) { 
    //创建渲染脚本上下文 
    Renderscript rs = Renderscript.create(context); 
 
    //为位图分配内存 
    Allocation allocation = Allocation.createFromBitmap(rs, bitmap); 
 
    Type t = allocation.getType(); 
 
    //用同样的类型创建内存,一般用这两种方式创建 Allocation 
    Allocation blurredAllocation = Allocation.createTyped(rs, t); 
 
    //创建高斯渲染脚本  
    scriptIntrinsicBlur blurscript = scriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 
    //设置模糊半径 (maximum 25.0) 
    blurscript.setRadius(radius); 
    //为脚本设置输入参数  
    blurscript.setInput(allocation); 
    //调用脚本 结果存入 blurredAllocation中 
    blurscript.forEach(blurredAllocation); 
 
    //把脚本结果存入位图中 因为为native层渲染,所以结果需要复制到上层 
    blurredAllocation.copyTo(bitmap); 
 
    //Destroy everything to free memory 
    allocation.destroy(); 
    blurredAllocation.destroy(); 
    blurscript.destroy(); 
    t.destroy(); 
 
    return bitmap; 
  } 

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/160615.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号