Example usage for android.renderscript Allocation destroy

List of usage examples for android.renderscript Allocation destroy

Introduction

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

Prototype

@Override
public void destroy() 

Source Link

Document

For USAGE_IO_OUTPUT, destroy() implies setSurface(null).

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap fastBlur(Context context, Bitmap bm, int radius) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Bitmap bitmap = bm.copy(bm.getConfig(), true);
        final RenderScript rs = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(rs, bm, Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        script.setRadius(radius);/*ww  w.  j a v a 2  s .  c o m*/
        script.setInput(input);
        script.forEach(output);
        output.copyTo(bitmap);

        // clean up renderscript resources
        rs.destroy();
        input.destroy();
        output.destroy();
        script.destroy();

        return bitmap;
    }
    return null;
}