I am trying to blur an image with ScriptIntrinsicBlur from the RenderScript support library. I am using gradle and I have used this approach to use the Support Library version of RenderScript.
On my Nexus 4, everything works fine and is really fast, but when I try it on my Samsung Galaxy S with Android 2.3.3, the picture that I get looks like this:
I am using Roman Nurik's tip for having the bitmap width as a multiple of 4, but I don't think that this is the cause of my problem. My blurring code looks exactly like in this post. Thanks for any advice.
Here's my code:
Getting Bitmap of the View and rescaling the Bitmap:
public static Bitmap loadBitmapFromView(View v) {
v.setDrawingCacheEnabled(false);
v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
return b;
}
public static Bitmap scaledBitmap(Bitmap dest, float scale) {
int scaledWidth = (int) (scale * dest.getWidth());
if (scaledWidth % 4 != 0) { //workaround for bug explained here https://plus.google.com/+RomanNurik/posts/TLkVQC3M6jW
scaledWidth = (scaledWidth / 4) * 4;
}
return Bitmap.createScaledBitmap(dest, scaledWidth, (int) (scale * dest.getHeight()), true);
}
Renderscript code:
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
I have noticed this error in the logcat output:
E/RenderScript_jni﹕ No GC methods
After that my application is frozen.