Andoridスクリーンショットコード

2715 ワード

エディタのロード中...
  
1     private Bitmap shot(Activity activity) {
2 // View View
3 View view = activity.getWindow().getDecorView();
4 view.setDrawingCacheEnabled(true);
5 view.buildDrawingCache();
6 Bitmap b1 = view.getDrawingCache();
7
8 //
9 Rect frame = new Rect();
10 activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
11 int statusBarHeight = frame.top;
12 Log.i("TAG", "" + statusBarHeight);
13
14 //
15 int width = activity.getWindowManager().getDefaultDisplay().getWidth();
16 int height = activity.getWindowManager().getDefaultDisplay().getHeight();
17 //
18 // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
19 Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
20 view.destroyDrawingCache();
21 return b;
22 }