Search in sources :

Example 6 with RSRuntimeException

use of android.renderscript.RSRuntimeException in project Blurry by wasabeef.

the class Blur method of.

public static Bitmap of(Context context, Bitmap source, BlurFactor factor) {
    int width = factor.width / factor.sampling;
    int height = factor.height / factor.sampling;
    if (Helper.hasZero(width, height)) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    PorterDuffColorFilter filter = new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.drawBitmap(source, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        try {
            bitmap = Blur.rs(context, bitmap, factor.radius);
        } catch (RSRuntimeException e) {
            bitmap = Blur.stack(bitmap, factor.radius, true);
        }
    } else {
        bitmap = Blur.stack(bitmap, factor.radius, true);
    }
    if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) {
        return bitmap;
    } else {
        Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true);
        bitmap.recycle();
        return scaled;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RSRuntimeException(android.renderscript.RSRuntimeException) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

RSRuntimeException (android.renderscript.RSRuntimeException)6 Bitmap (android.graphics.Bitmap)5 Canvas (android.graphics.Canvas)5 Paint (android.graphics.Paint)5 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 Allocation (android.renderscript.Allocation)1 FileA3D (android.renderscript.FileA3D)1 Mesh (android.renderscript.Mesh)1 RenderScript (android.renderscript.RenderScript)1 ScriptIntrinsicBlur (android.renderscript.ScriptIntrinsicBlur)1