Android 用 RenderScript 高斯模糊后,花成一片,到底咋回事儿?有没有大神来解答一下,谢谢!
代码如下:
private static Bitmap rsBlur(Context context, Bitmap source, int radius){
//(1)
RenderScript renderScript = RenderScript.create(context);
// Allocate memory for Renderscript to work with
//(2)
final Allocation input = Allocation.createFromBitmap(renderScript, source);
final Allocation output = Allocation.createTyped(renderScript,input.getType());
//(3)
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
//(4)
scriptIntrinsicBlur.setInput(input);
//(5)
// Set the blur radius
scriptIntrinsicBlur.setRadius(radius);
//(6)
// Start the ScriptIntrinisicBlur
scriptIntrinsicBlur.forEach(output);
//(7)
// Copy the output to the blurred bitmap
output.copyTo(source);
//(8)
renderScript.destroy();
return source;
}
效果如下
照片是把drawable转为bitmap,然后再进行模糊化处理,结果就成这样了,有没有大神来看看咋回事啊?