Example usage for android.view View destroyDrawingCache

List of usage examples for android.view View destroyDrawingCache

Introduction

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

Prototype

@Deprecated
public void destroyDrawingCache() 

Source Link

Document

Frees the resources used by the drawing cache.

Usage

From source file:Main.java

public static Bitmap getBitmapFromView(View paramView) {
    paramView.destroyDrawingCache();
    paramView.measure(View.MeasureSpec.makeMeasureSpec(0, 0), View.MeasureSpec.makeMeasureSpec(0, 0));
    paramView.layout(0, 0, paramView.getMeasuredWidth(), paramView.getMeasuredHeight());
    paramView.setDrawingCacheEnabled(true);
    return paramView.getDrawingCache(true);
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    view.destroyDrawingCache();
    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.setDrawingCacheEnabled(true);/*  w w  w .j ava2 s .c om*/
    Bitmap bitmap = view.getDrawingCache(true);
    return bitmap;
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true);/*from  ww w  . j av a2s  .  com*/
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    view.destroyDrawingCache();
    return bitmap;
}

From source file:Main.java

public static void releaseResources(View view) {
    if (view != null) {
        if (view instanceof ListView) {
            ((ListView) view).setAdapter(null);
        }//from ww  w.j a v  a 2 s  . co  m
        view.setVisibility(View.GONE);
        view.destroyDrawingCache();
        view = null;
    }
}

From source file:Main.java

public static Bitmap getViewBitmap(View view) {
    view.setDrawingCacheEnabled(true); // for getCanvasBitmap
    view.buildDrawingCache();/*ww  w  .j av  a 2 s  . c o m*/
    Bitmap bitmap = view.getDrawingCache();
    if (bitmap == null) {
        return null;
    }
    view.destroyDrawingCache();
    return bitmap;
}

From source file:Main.java

public static Bitmap snapShotWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*from  ww w .j a  v  a2s .com*/
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int[] screen = getWidthAndHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, screen[0], screen[1]);
    view.destroyDrawingCache();
    return bp;

}

From source file:Main.java

public static Bitmap snapShotWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*from   www .jav a 2 s  .  c  om*/
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
    view.destroyDrawingCache();
    return bp;

}

From source file:Main.java

/**
 * Convert a view to a bitmap./*from  w  w w.java2 s  .  c  om*/
 *
 * @param view the view to convert
 * @return the converted bitmap
 */
public static Bitmap createBitmapFromView(@NonNull View view) {
    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
    view.buildDrawingCache();

    if (view.getDrawingCache() == null) {
        return null;
    }

    Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    view.destroyDrawingCache();
    return snapshot;
}

From source file:Main.java

public static Bitmap captureWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*from   w ww. j  ava2s  .  co  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;
}

From source file:com.dv.Utils.Tools.java

/**
 * view?bitmap/* ww  w .ja v  a  2  s. c  o m*/
 *
 * @param view
 * @return
 */
public static Bitmap convertViewToBitmap(View view) {
    view.destroyDrawingCache();
    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.setDrawingCacheEnabled(true);

    Bitmap bitmap = view.getDrawingCache(true);

    return bitmap;
}