如何在Android中模糊触摸区域

问题描述 投票:-1回答:1

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

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;
}

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

java android image-processing photo blur
1个回答
1
投票

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

  1. 您可以使用ScriptIntrinsicBlur渲染脚本。在那种情况下,在分配对象中填充像素时,您只需要用需要模糊的像素填充“ tmpIn”分配对象即可。然后,在模糊结束后,您必须用“ tmpOut”分配对象的像素替换原始图像的特定像素。
  2. 或者您可以编写您的自定义渲染脚本来仅模糊特定像素。

希望有帮助。让我知道,如果我能进一步帮助您。编码愉快:)

© www.soinside.com 2019 - 2024. All rights reserved.