Example usage for android.renderscript Allocation getElement

List of usage examples for android.renderscript Allocation getElement

Introduction

In this page you can find the example usage for android.renderscript Allocation getElement.

Prototype

public Element getElement() 

Source Link

Document

Get the android.renderscript.Element of the android.renderscript.Type of the Allocation.

Usage

From source file:Main.java

public static void blur(Context context, Bitmap bkg, View view, int width, int height) {
    float radius = 20;
    Log.i("hulixia", bkg.getWidth() + "w,h" + bkg.getDensity());
    Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft(), -view.getTop());
    canvas.drawBitmap(bkg, 0, 0, null);/*from ww w  .ja  v  a  2  s.co  m*/

    RenderScript rs = RenderScript.create(context);

    Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay);
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
    blur.setInput(overlayAlloc);
    blur.setRadius(radius);
    blur.forEach(overlayAlloc);
    overlayAlloc.copyTo(overlay);
    view.setBackground(new BitmapDrawable(context.getResources(), overlay));
    rs.destroy();
}

From source file:com.hellofyc.base.util.ViewUtils.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static void blur(Context context, View view) {
    view.buildDrawingCache();//from   w w  w  . j a v  a2  s.c  o m
    Bitmap srcBitmap = view.getDrawingCache();
    float radius = 20f;

    Bitmap overlay = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft(), -view.getTop());
    canvas.drawBitmap(srcBitmap, 0, 0, null);

    RenderScript script = RenderScript.create(context);
    Allocation allocation = Allocation.createFromBitmap(script, overlay);
    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(script, allocation.getElement());
    blur.setInput(allocation);
    blur.setRadius(radius);
    blur.forEach(allocation);
    allocation.copyTo(overlay);

    view.setBackground(new BitmapDrawable(context.getResources(), overlay));

    script.destroy();
}