/**
* 获取指定Activity的截屏
*
* @param activity
* @return
*/
private Bitmap getBitmap(Activity activity) {
// View是你需要截图的View
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap originalBitmap = view.getDrawingCache();
// 获取状态栏高度
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
// 获取屏幕长和高
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
// 去掉标题栏
Bitmap bitmap = Bitmap.createBitmap(originalBitmap, 0, statusBarHeight, width, height - statusBarHeight);
view.destroyDrawingCache();
return bitmap;
}
屏幕截图
最新推荐文章于 2022-05-10 17:18:10 发布