获取当前屏幕截图,不包含状态栏
程序员文章站
2022-05-28 22:40:36
...
/** * 获取当前屏幕截图,不包含状态栏 * @param activity * @return bp */ public static Bitmap snapShotWithoutStatusBar(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); if (bmp == null) { return null; } Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; Bitmap bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, bmp.getWidth(), bmp.getHeight() - statusBarHeight); view.destroyDrawingCache(); view.setDrawingCacheEnabled(false); return bp; }
Bitmap map = ScreenUtil.snapShotWithoutStatusBar(MainActivity.this); img.setImageBitmap(map);
下一篇: TextView展开收起,资料收集