获得屏幕截图代码:不包括状态栏

来源:互联网 发布:qt4.7.4下载 windows 编辑:程序博客网 时间:2024/05/15 07:01
    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;    }
0 0