I have some problems with the RenderScript ScriptIntrinsic Blur - on some devices it doesn't blur the whole image. I downscale the input image and make sure that the width is a multiple of 4 (because it's suggested by Roman Nurik: https://plus.google.com/+RomanNurik/posts/TLkVQC3M6jW)
@SuppressLint("NewApi")
private Bitmap blurRenderScript(Bitmap smallBitmap) {
Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), smallBitmap.getConfig());
RenderScript rs = RenderScript.create(getContext());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation inAlloc = Allocation.createFromBitmap(rs, smallBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
Allocation outAlloc = Allocation.createFromBitmap(rs, output);
script.setRadius(BLUR_RADIUS);
script.setInput(inAlloc);
script.forEach(outAlloc);
outAlloc.copyTo(output);
rs.destroy();
MutableBitmap.delete(smallBitmap);
return output;
}
It is working on a Nexus 4:
But on a Galaxy S4 the right side has a transparent edge:
I hope you can see what I mean - if you open the picture in gimp or so you can see it better. It doesn't depend on the picture size. I Also tried it with bigger and smaller images, and the result was always the same. It also happens on a Nexus 7 2012 for example. Also, the transparent artifacts are sometimes on the bottem or left edge. Thanks in advance for your help!
Nexus 4: 4.4.2/Build Number KOT49H Galaxy S4: 4.2.2/Build Number JDQ39.I9505XXUDMGG
I'm not sure why this might work, but for me it did..
Try instead of
Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), smallBitmap.getConfig());
pass in Bitmap.Config.ARGB_8888 like so
Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.ARGB_8888);
I am assuming you are using android.renderscript instead of the support lib android.v8.renderscript. (or a old support lib?)
If that is true, then it is a known bug that can only be fixed by a system upgrade, which may not be feasible to the users.
One way to workaround this is to use RenderScript Support lib: you can find the detailed instructions here:http://developer.android.com/guide/topics/renderscript/compute.html#access-rs-apis
Basically you just need to change the import:
import android.support.v8.renderscript.*;
And config your build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}
}
There are several advantages of using support lib:
On the downside, to achieve this, it needs to bundle several shared libraries which will make your app beefier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With