直接上代码,亲测有用
private static Bitmap takeScreenShot(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = 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 b = Bitmap.createBitmap(bitmap, 0,
statusBarHeight, width, height - statusBarHeight);
view.destroyDrawingCache();
return b;
}