I am trying to blur bitmaps in my app using RenderScript framework. I am using the following code:
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius)
{
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;
}
Unfortunately all I get with the code is black bitmaps. How can I fix the issue?
Bitmaps passed to the apply
method are created in the following way:
Bitmap b = Bitmap.createBitmap(thisView.getWidth(),
thisView.getHeight(),
Bitmap.Config.ARGB_8888);
The width and height of these bitmaps are multiples of 4.
There are also some errors reported by RenderScript but I don't know what they means and how should I fix them (the documentation for ScriptIntrinsicBlur
is rather thin). Here are these errors:
20305-20391/com.xxx E/RenderScript﹕ rsi_ScriptIntrinsicCreate 5
20305-20391/com.xxx E/RenderScript﹕ rsAssert failed: mUserRefCount > 0, in
frameworks/rs/rsObjectBase.cpp at 112
EDIT:
The radius is 5 and I am running the app on Samsung Galaxy Nexus with Android 4.2.1.