Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blur a bitmap with Renderscript and more than 25 radius Android

I have blurred a bitmap with Androids Rederscript

private Bitmap createBitmap_ScriptIntrinsicBlur(Bitmap src, float r) {

    //Radius range (0 < r <= 25)
    if(r <= 0){
        r = 0.1f;
    }else if(r > 25){
        r = 25.0f;
    }
    Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(),Bitmap.Config.ARGB_8888);

    RenderScript renderScript = RenderScript.create(getActivity());

    Allocation blurInput = Allocation.createFromBitmap(renderScript, src);
    Allocation blurOutput = Allocation.createFromBitmap(renderScript, bitmap);

    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(renderScript,Element.U8_4(renderScript));
    blur.setInput(blurInput);
    blur.setRadius(r);
    blur.forEach(blurOutput);

    blurOutput.copyTo(bitmap);
    renderScript.destroy();
    return bitmap;
}

But the image isn't blurred enough. Are there any possibilities to blur the image with a radius over 25. And when I call the blur function multiple times the image stays as blurred as a single function call.So that doesn't work either.
Thank you for your help.

like image 688
RoterBaron Avatar asked Feb 21 '16 17:02

RoterBaron


1 Answers

  1. Scale the image down by a factor of 4-8.
  2. Run blur with 25 px radius.
  3. Scale back up to the original size.
like image 168
Miloslaw Smyk Avatar answered Oct 06 '22 18:10

Miloslaw Smyk