Background
There are plenty of places (including here) to show how to use Renderscript to blur images, as such:
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Context context, Bitmap srcBitmap, @FloatRange(from = 0.0f, to = 25.0f) float radius) {
if (srcBitmap == null)
return null;
Bitmap outputBitmap = null;
RenderScript rs = null;
try {
rs = RenderScript.create(context);
outputBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(outputBitmap);
canvas.drawBitmap(srcBitmap, 0, 0, null);
Allocation overlayAlloc = Allocation.createFromBitmap(rs, outputBitmap);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setInput(overlayAlloc);
blur.setRadius(radius);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(outputBitmap);
return outputBitmap;
} catch (Exception ex) {
if (outputBitmap != null)
outputBitmap.recycle();
return srcBitmap;
} finally {
if (rs != null)
rs.destroy();
}
}
The problem
Usually it works great, but when using some images and/or radius-settings, the output image has artifacts that look like scan-lines:
What I've tried
I've found that there is a nicer blurring solutions (like here), but they don't use Renderscript and are also slow and memory-consuming.
I've also tried to make the input image smaller, but the output still has scanlines artifacts.
Finally, I've also reported about this, here.
The question
Is it possible to use Renderscript to blur images without those Artifcats? Is there anything wrong with what I wrote?