Example usage for android.renderscript ScriptIntrinsicBlur create

List of usage examples for android.renderscript ScriptIntrinsicBlur create

Introduction

In this page you can find the example usage for android.renderscript ScriptIntrinsicBlur create.

Prototype

public static ScriptIntrinsicBlur create(RenderScript rs, Element e) 

Source Link

Document

Create an intrinsic for applying a blur to an allocation.

Usage

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap blurRenderScript(Bitmap bmImage, int radius, View v) {
    final float BITMAP_SCALE = 0.4f;
    final float BLUR_RADIUS = 7.5f;

    int width = Math.round(bmImage.getWidth() * BITMAP_SCALE);
    int height = Math.round(bmImage.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(bmImage, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(v.getContext());
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    //Allocation tmpIn = Allocation.createFromBitmap(rs, bmImage,
    //      Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    //Allocation tmpOut = Allocation.createTyped(rs, tmpIn.getType());
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    theIntrinsic.setRadius(radius);/* w w  w.j  a  v  a2  s  .  c  o  m*/
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public Image gaussianBlurImage(Image image, float radius) {
    try {//w w w. ja v  a2 s . c  om
        Bitmap outputBitmap = Bitmap.createBitmap((Bitmap) image.getImage());

        RenderScript rs = RenderScript.create(getContext());
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, (Bitmap) image.getImage());
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(radius);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return new NativeImage(outputBitmap);
    } catch (Throwable t) {
        brokenGaussian = true;
        return image;
    }
}