private static Bitmap takeScreenShot(Activity activity) {
View view = activity.getWindow().getDecorView().getRootView();
Bitmap b = null;
try{
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getRootView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay()
.getHeight();
b = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width,
height - statusBarHeight);
}catch (Exception e){
}finally {
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
}
return b;
}
获得屏幕截图代码:不包括状态栏
最新推荐文章于 2019-11-27 18:34:31 发布