Android 模糊处理RenderScript
作者:互联网
RendScript 是一种低级的高性能编程语言,用于3D渲染和处理密集型计算(3D播放等和关于CPU密集型的计算)。功能很强大,玩得好要熟悉计算机图像。但自带模糊接口。
public static Bitmap blurBitmap(Bitmap bitmap, float radius, Context context) {
//Create renderscript
RenderScript rs = RenderScript.create(context);
//Create allocation from Bitmap
Allocation allocation = Allocation.createFromBitmap(rs, bitmap);
Type t = allocation.getType();
//Create allocation with the same type
Allocation blurredAllocation = Allocation.createTyped(rs, t);
//Create script
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
//Set blur radius (maximum 25.0)
blurScript.setRadius(radius);
//Set input for script
blurScript.setInput(allocation);
//Call script for output allocation
blurScript.forEach(blurredAllocation);
//Copy script result into bitmap
blurredAllocation.copyTo(bitmap);
//Destroy everything to free memory
allocation.destroy();
blurredAllocation.destroy();
blurScript.destroy();
//t.destroy();原本是有这一行的。添加直接报错。网上没找到说法,去掉能直接运行。
rs.destroy();
return bitmap;
}
上面是抄的代码,实测有效。红色部分略有疑问。
标签:Allocation,rs,模糊,RenderScript,bitmap,allocation,blurScript,destroy,Android 来源: https://blog.csdn.net/weixin_39821531/article/details/88741339