高斯模糊

  1. RenderScript是Android在API 11之后加入的,用于高效的图片处理,包括模糊、混合、矩阵卷积计算等,代码示例如下
  2. public Bitmap blurBitmap(Bitmap bitmap){  
  3.           
  4.         //Let's create an empty bitmap with the same size of the bitmap we want to blur  
  5.         Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);  
  6.           
  7.         //Instantiate a new Renderscript  
  8.         RenderScript rs = RenderScript.create(getApplicationContext());  
  9.           
  10.         //Create an Intrinsic Blur Script using the Renderscript  
  11.         ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));  
  12.           
  13.         //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps  
  14.         Allocation allIn = Allocation.createFromBitmap(rs, bitmap);  
  15.         Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);  
  16.           
  17.         //Set the radius of the blur  
  18.         blurScript.setRadius(25.f);  
  19.           
  20.         //Perform the Renderscript  
  21.         blurScript.setInput(allIn);  
  22.         blurScript.forEach(allOut);  
  23.           
  24.         //Copy the final bitmap created by the out Allocation to the outBitmap  
  25.         allOut.copyTo(outBitmap);  
  26.           
  27.         //recycle the original bitmap  
  28.         bitmap.recycle();  
  29.           
  30.         //After finishing everything, we destroy the Renderscript.  
  31.         rs.destroy();  
  32.           
  33.         return outBitmap;     
  34.     }  
blurScript.setRadius(25.f); 
 设置模糊程度,参数越大,越模糊,参数范围为0-25,否则会报错:
android.renderscript.RSIllegalArgumentException: Radius out of range (0 < r <= 25).


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值