安卓截圖無狀態欄

private Bitmap getShotWithoutBar(){
    //獲取windows最頂層的view
    View view = this.getWindow().getDecorView();
    view.buildDrawingCache();

    //獲取狀態欄
    Rect rect = new Rect();
    view.getWindowVisibleDisplayFrame(rect);
    int statusBarHeight = rect.top;


    //獲取屏幕寬高
    Display display = this.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width= size.x;
    int height= size.y;

    //允許當前窗口保存緩存信息
    view.setDrawingCacheEnabled(true);

    //去掉狀態欄
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(),0,
            statusBarHeight,width,height-statusBarHeight);

    //銷燬緩存信息
    view.destroyDrawingCache();

    return bitmap;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章