0

I am doing screenshot and returning a bitmap using the next method.

 public Bitmap takeScreenShot(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;
    }

and i call it something like this

takeScreenShot(getWindow().getDecorView().findViewById(android.R.id.content))

My problem is that i have some layout that contain listviews/gridviews , how can i screenshot the entire layout extended ?

ask110593
  • 123
  • 1
  • 1
  • 9

1 Answers1

0

Try this code:

public static Bitmap getBitmapFromView(View v, int width, int height) {
    Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);                
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
    v.draw(c);
    return b;
}

Edit:

Bitmap bitmap = Bitmap.createBitmap(scrollView.getChildAt(0).getWidth(), scrollView.getChildAt(0).getHeight(), Bitmap.Config.ARGB_8888);
jlopez
  • 6,287
  • 2
  • 51
  • 90