Search in sources :

Example 41 with Allocation

use of android.renderscript.Allocation in project SmartCampus by Vegen.

the class CommonUtils method blur.

public static void blur(Bitmap bkg, View view, ImageView forecastBlur) {
    long start = System.currentTimeMillis();
    float radius = 18;
    float scaleFactor = 1.0f;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor), (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        // canvas.translate(-view.getLeft(), -view.getTop());
        canvas.scale(1 / scaleFactor, 1 / scaleFactor);
        canvas.drawBitmap(bkg, 0, 0, null);
        RenderScript rs = RenderScript.create(MyApplication.getInstance());
        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);
        forecastBlur.setImageDrawable(new BitmapDrawable(MyApplication.getInstance().getResources(), overlay));
        rs.destroy();
    }
    Log.e("cost", System.currentTimeMillis() - start + "");
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) Allocation(android.renderscript.Allocation) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 42 with Allocation

use of android.renderscript.Allocation in project vlc-android by videolan.

the class UiTools method blurBitmap.

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blurBitmap(Bitmap bitmap, float radius) {
    if (bitmap == null || bitmap.getConfig() == null)
        return null;
    // Let's create an empty bitmap with the same size of the bitmap we want to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    // Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
    // Create an Intrinsic Blur Script using the Renderscript
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    // Set the radius of the blur
    blurScript.setRadius(radius);
    // Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    // Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(outBitmap);
    // After finishing everything, we destroy the Renderscript.
    rs.destroy();
    return outBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Allocation(android.renderscript.Allocation) RequiresApi(android.support.annotation.RequiresApi)

Example 43 with Allocation

use of android.renderscript.Allocation in project SmartMesh_Android by SmartMeshFoundation.

the class BitmapUtils method blurBitmap.

public static Bitmap blurBitmap(Context context, Bitmap sentBitmap) {
    if (Build.VERSION.SDK_INT > 16) {
        try {
            Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), false);
            final RenderScript rs = RenderScript.create(context);
            final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
            final Allocation output = Allocation.createTyped(rs, input.getType());
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(12.0f);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(bitmap);
            return bitmap;
        } catch (Exception e) {
            return sentBitmap;
        } catch (OutOfMemoryError err) {
            return sentBitmap;
        }
    } else {
        return sentBitmap;
    }
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) Allocation(android.renderscript.Allocation) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) IOException(java.io.IOException)

Example 44 with Allocation

use of android.renderscript.Allocation in project PolarrCameraAndroidSDK by Polarrco.

the class MainActivity method showYuv.

private void showYuv(byte[] yuvData) {
    Allocation bmData = null;
    bmData = renderScriptNV21ToRGBA888(this, stride, scanline, yuvData);
    Bitmap stitchBmp = Bitmap.createBitmap(stride, scanline, Bitmap.Config.ARGB_8888);
    bmData.copyTo(stitchBmp);
    // stitchBmp = getRotatedImage(stitchBmp, 90);
    final Bitmap finalStitchBmp = stitchBmp;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            imageView.setImageBitmap(finalStitchBmp);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) Allocation(android.renderscript.Allocation)

Example 45 with Allocation

use of android.renderscript.Allocation in project vlc-android by GeoffreyMetais.

the class UiTools method blurBitmap.

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blurBitmap(Bitmap bitmap, float radius) {
    if (bitmap == null || bitmap.getConfig() == null)
        return null;
    // Let's create an empty bitmap with the same size of the bitmap we want to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    // Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
    // Create an Intrinsic Blur Script using the Renderscript
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    // Set the radius of the blur
    blurScript.setRadius(radius);
    // Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    // Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(outBitmap);
    // After finishing everything, we destroy the Renderscript.
    rs.destroy();
    return outBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Allocation(android.renderscript.Allocation) RequiresApi(android.support.annotation.RequiresApi)

Aggregations

Allocation (android.renderscript.Allocation)71 Bitmap (android.graphics.Bitmap)42 RenderScript (android.renderscript.RenderScript)42 ScriptIntrinsicBlur (android.renderscript.ScriptIntrinsicBlur)41 SuppressLint (android.annotation.SuppressLint)14 RequiresApi (android.support.annotation.RequiresApi)14 TargetApi (android.annotation.TargetApi)10 Type (android.renderscript.Type)6 SdkConstantType (android.annotation.SdkConstant.SdkConstantType)5 Paint (android.graphics.Paint)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 BitmapFactory (android.graphics.BitmapFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Element (android.renderscript.Element)2 Script (android.renderscript.Script)2 RequiresApi (androidx.annotation.RequiresApi)2 ArrayList (java.util.ArrayList)2