Example usage for android.renderscript ScriptIntrinsicBlur forEach

List of usage examples for android.renderscript ScriptIntrinsicBlur forEach

Introduction

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

Prototype

public void forEach(Allocation aout) 

Source Link

Document

Apply the filter to the input and save to the specified 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);//from ww  w . j  a  v a2s  . co  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 {/*from  w w  w . j  ava  2s .c o  m*/
        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;
    }
}