獲得屏幕截圖代碼:不包括狀態欄


    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;
    }
發佈了74 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章