簡體   English   中英

如何在 Android 中模糊觸摸區域

[英]How to Blur Touched Area in Android

我正在嘗試模糊 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;
}

如何模糊用戶在屏幕上觸摸的區域?

它模糊了整個圖像,因為 ScriptIntrinsicBlur 渲染腳本為每個像素運行。 現在為了僅模糊特定像素,您需要首先找出要模糊的像素。 然后要模糊它們,您有兩種可能的方法。

  1. 您可以使用 ScriptIntrinsicBlur 渲染腳本。 在這種情況下,在填充分配對象中的像素時,您必須僅使用需要模糊的像素填充“tmpIn”分配對象。 然后在模糊完成后,您必須用“tmpOut”分配對象的像素替換原始圖像的特定像素。
  2. 或者您可以編寫自定義渲染腳本以僅模糊特定像素。

希望能幫助到你。 如果我能進一步幫助你,請告訴我。 快樂編碼:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM