Example usage for android.graphics Bitmap createBitmap

List of usage examples for android.graphics Bitmap createBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createBitmap.

Prototype

public static @NonNull Bitmap createBitmap(@NonNull Picture source) 

Source Link

Document

Creates a Bitmap from the given Picture source of recorded drawing commands.

Usage

From source file:Main.java

public static Bitmap blur(final Context context, final Bitmap image) {
    if (null == image)
        return null;

    Bitmap outputBitmap = Bitmap.createBitmap(image);
    final RenderScript renderScript = RenderScript.create(context);
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

    //Intrinsic Gausian blur filter
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);//from   ww w .  j  a  v  a 2 s. com
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true);/*from   w ww .j  av a 2 s  .  co  m*/
    view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache(true);
    Bitmap bm = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    return bm;
}