First i loaded a icon to drawable and converted it to Bitmap, and i blur it by using Renderscript.
defautIcon = ImageUtils.drawableToBitmap(notification.getLargeIcon().loadDrawable(this));
largeIcon = RenderScriptBlur.blur(getContext(), defauticon, 15);
and here is method ImageUtils.drawableToBitmap
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable == null)
return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null)
return bitmapDrawable.getBitmap();
}
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0)
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
else
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
and here is Renderscript and method blur
public class RenderScriptBlur {
private static final float BITMAP_SCALE = 0.4f;
private static final int BLUR_RADIUS = 7;
public static Bitmap blur(Context context, Bitmap bitmap) {
return blur(context, bitmap, BITMAP_SCALE, BLUR_RADIUS);
}
public static Bitmap blur(Context context, Bitmap bitmap, float bitmap_scale) {
return blur(context, bitmap, bitmap_scale, BLUR_RADIUS);
}
public static Bitmap blur(Context context, Bitmap bitmap, int blur_radius) {
return blur(context, bitmap, BITMAP_SCALE, blur_radius);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(Context context, Bitmap bitmap, float bitmap_scale, int blur_radius) {
Bitmap inputBitmap = Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * bitmap_scale),
Math.round(bitmap.getHeight() * bitmap_scale), false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(blur_radius);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
rs.destroy();
bitmap.recycle();
return outputBitmap;
}
}
and finally i got this broken image. I dont know why...Please help
broken image: