Example usage for android.view View buildDrawingCache

List of usage examples for android.view View buildDrawingCache

Introduction

In this page you can find the example usage for android.view View buildDrawingCache.

Prototype

@Deprecated
public void buildDrawingCache() 

Source Link

Document

Calling this method is equivalent to calling buildDrawingCache(false).

Usage

From source file:Main.java

public static Bitmap convertViewToBitmap(View view) {
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    return bitmap;
}

From source file:Main.java

public static Bitmap takeScreenShot(View view) {
    view.setDrawingCacheEnabled(true);//from www  .ja  va2 s.  c om
    view.buildDrawingCache();
    return view.getDrawingCache();
}

From source file:Main.java

public static Bitmap viewToBitmap(View view) {
    view.setDrawingCacheEnabled(true);//from ww w  . j a  v  a2  s. c  om
    view.buildDrawingCache();
    Bitmap bm = view.getDrawingCache();
    return bm;
}

From source file:Main.java

public static Bitmap captureView(View v) {
    v.setDrawingCacheEnabled(true);
    v.buildDrawingCache();
    return v.getDrawingCache();
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true);//ww  w . j  ava 2s .c o m
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    return bitmap;
}

From source file:Main.java

/**
 * get view screen shot bitmap./*from   www  .j a v a  2  s .  c o m*/
 * @param v the view
 * @return bitmap
 */
public static Bitmap capture(View v) {
    v.setDrawingCacheEnabled(true);
    v.buildDrawingCache();
    Bitmap bitmap = v.getDrawingCache();
    v.setDrawingCacheEnabled(false);
    return bitmap;
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true); // for getCanvasBitmap
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    if (bitmap == null) {
        return null;
    }/*ww  w.jav  a2s .  com*/
    view.destroyDrawingCache();
    return bitmap;
}

From source file:Main.java

/**
 * get activity screen shot bitmap. system status bar is not included.
 * @param activity the activity/*  w w  w. j a v a  2s.  c om*/
 * @return bitmap
 */
public static Bitmap capture(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();

    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();
    Bitmap b = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
}

From source file:Main.java

public static Bitmap getCrop(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.buildDrawingCache();

    Rect rect = new Rect();
    view.getWindowVisibleDisplayFrame(rect);
    int stateBarHeight = rect.top;

    view.setDrawingCacheEnabled(true);//from w w  w . j av  a  2  s  . com

    Bitmap bmpCache = view.getDrawingCache();
    Bitmap bmp = Bitmap.createBitmap(bmpCache, 0, stateBarHeight, bmpCache.getWidth(),
            bmpCache.getHeight() - stateBarHeight);

    view.destroyDrawingCache();

    return bmp;
}

From source file:Main.java

public static Bitmap captureWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*from  ww  w.  j  av  a  2 s  .  c  o m*/
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap ret = Bitmap.createBitmap(bmp, 0, 0, dm.widthPixels, dm.heightPixels);
    view.destroyDrawingCache();
    return ret;
}