Example usage for android.view View setDrawingCacheQuality

List of usage examples for android.view View setDrawingCacheQuality

Introduction

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

Prototype

@Deprecated
public void setDrawingCacheQuality(@DrawingCacheQuality int quality) 

Source Link

Document

Set the drawing cache quality of this view.

Usage

From source file:Main.java

/**
 * Convert a view to a bitmap./*from w  w  w  .ja  va2  s . c o  m*/
 *
 * @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:com.zoffcc.applications.zanavi.Navit.java

static void take_map_screenshot(String dir_name, String name_base) {
    try {//from  www. j  av  a2s.  co  m
        View v1 = Navit.N_NavitGraphics.view;
        v1.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        v1.setDrawingCacheEnabled(true);
        Bitmap bm = v1.getDrawingCache();

        FileOutputStream out = null;
        try {
            out = new FileOutputStream(dir_name + "/" + name_base + ".png");
            bm.compress(Bitmap.CompressFormat.PNG, 100, out);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("TSCR:004 " + e.getMessage());
        } finally {
            v1.setDrawingCacheEnabled(false);

            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e4) {
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void take_phone_screenshot(Activity a, String dir_name, String name_base) {
    try {//from   www  .j  a va  2s  .c o m
        View v1 = a.getWindow().getDecorView().getRootView();
        v1.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        v1.setDrawingCacheEnabled(true);
        Bitmap bm = v1.getDrawingCache();

        FileOutputStream out = null;
        try {
            out = new FileOutputStream(dir_name + "/" + name_base + ".png");
            bm.compress(Bitmap.CompressFormat.PNG, 100, out);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("TSCR:004 " + e.getMessage());
        } finally {
            v1.setDrawingCacheEnabled(false);

            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e4) {
    }
}