简体   繁体   English

使用Renderscript和超过25个半径的Android模糊位图

[英]Blur a bitmap with Renderscript and more than 25 radius Android

I have blurred a bitmap with Androids Rederscript 我用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. 有没有可能模糊半径超过25的图像。当我多次调用模糊功能时,图像会像单个函数调用一样模糊。所以这也不起作用。
Thank you for your help. 谢谢您的帮助。

  1. Scale the image down by a factor of 4-8. 将图像缩小4-8倍。
  2. Run blur with 25 px radius. 以25像素半径运行模糊。
  3. Scale back up to the original size. 缩小到原始大小。

I know you said that running it multiple times doesn't work, but here's what I'm doing. 我知道你说多次运行它不起作用,但这就是我正在做的事情。

Bitmap inputBitmap = Bitmap.createScaledBitmap(artistImage, artistImage.getWidth(), artistImage.getHeight(), false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

RenderScript rs = RenderScript.create(context);

for (int i = 0; i < 10; i++){
    final Allocation input = Allocation.createFromBitmap(rs, outputBitmap); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory
    final Allocation output = Allocation.createTyped(rs, input.getType());
    final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    script.setRadius(25F);
    script.setInput(input);
    script.forEach(output);
    output.copyTo(outputBitmap);
}

You may have been running a blur on your normal source image multiple times, which obviously wouldn't accomplish anything. 你可能已经多次在普通源图像上运行模糊,这显然无法完成任何事情。 This works for me, and can blur it an incredible amount depending on what i is. 这对我有用,并且可以根据i情况将其模糊不清。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM