1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| /** * Return the bitmap of screen. * * @param activity The activity. * @return the bitmap of screen */ public static Bitmap screenShot(@NonNull final Activity activity) { return screenShot(activity, false); }
/** * Return the bitmap of screen. * * @param activity The activity. * @param isDeleteStatusBar True to delete status bar, false otherwise. * @return the bitmap of screen */ public static Bitmap screenShot(@NonNull final Activity activity, boolean isDeleteStatusBar) { View decorView = activity.getWindow().getDecorView(); Bitmap bmp = view2Bitmap(decorView); DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); if (isDeleteStatusBar) { int statusBarHeight = XSystemUI.getStatusBarHeight(); return Bitmap.createBitmap( bmp, 0, statusBarHeight, dm.widthPixels, dm.heightPixels - statusBarHeight ); } else { return Bitmap.createBitmap(bmp, 0, 0, dm.widthPixels, dm.heightPixels); } }
|