如何在安卓中模糊触摸区域



>我正在尝试模糊安卓中的触摸区域。 下面的代码模糊了整个图像。但我想模糊屏幕上的触摸区域。

public static Bitmap blur(Context context, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}

如何模糊用户在屏幕上触摸的区域?

它模糊了整个图像,因为 ScriptIntrinsicBlur 渲染脚本为每个像素运行。现在,为了仅模糊特定像素,您需要首先找出要模糊的像素。然后要模糊它们,您有两种可能的方法。

  1. 您可以使用 ScriptIntrinsicBlur 渲染脚本。在这种情况下,在填充分配对象中的像素时,您必须仅使用需要模糊的像素填充"tmpIn"分配对象。然后,在模糊完成后,您必须将原始图像的特定像素替换为"tmpOut"分配对象的像素。
  2. 或者,您可以编写自定义渲染脚本以仅模糊特定像素。

希望对您有所帮助。如果我能进一步帮助您,请告诉我。快乐的编码:)

最新更新