Example usage for android.renderscript Element U8_4

List of usage examples for android.renderscript Element U8_4

Introduction

In this page you can find the example usage for android.renderscript Element U8_4.

Prototype

public static Element U8_4(RenderScript rs) 

Source Link

Usage

From source file:com.slownet5.pgprootexplorer.filemanager.ui.TabsFragmentOne.java

public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

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

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);/*from w  w  w.ja v a  2s . co m*/
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
    } else {
        outputBitmap = BlurHelper.doBlur(image, (int) BLUR_RADIUS, false);
    }

    return outputBitmap;

}

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);//www .  ja v a  2s  .c om
    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  a  v  a  2  s.  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;
    }
}