中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

android中實現(xiàn)整個屏幕截圖的代碼

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

android開發(fā)中實現(xiàn)整個屏幕截圖,首先通過activity對象的getwindow()方法獲得整個屏幕的window對象,再通過整個屏幕的window對象的getDecorView()方法獲得整個屏幕的view,最后截圖的實現(xiàn),也就是將view轉換成bitmap,然后,將bitmap保存為圖片文件。

android中實現(xiàn)整個屏幕截圖的代碼
public static Bitmap takeScreenShot(Activity act) {  
    if (act == null || act.isFinishing()) {  
        Log.d(TAG, "act參數(shù)為空.");  
        return null;  
    }  
 
    // 獲取當前視圖的view  
    View scrView = act.getWindow().getDecorView();  
    scrView.setDrawingCacheEnabled(true);  
    scrView.buildDrawingCache(true);  
 
    // 獲取狀態(tài)欄高度  
    Rect statuBarRect = new Rect();  
    scrView.getWindowVisibleDisplayFrame(statuBarRect);  
    int statusBarHeight = statuBarRect.top;  
    int width = act.getWindowManager().getDefaultDisplay().getWidth();  
    int height = act.getWindowManager().getDefaultDisplay().getHeight();  
 
    Bitmap scrBmp = null;  
    try {  
        // 去掉標題欄的截圖  
        scrBmp = Bitmap.createBitmap( scrView.getDrawingCache(), 0, statusBarHeight,  
                width, height - statusBarHeight);  
    } catch (IllegalArgumentException e) {  
        Log.d("", "#### 旋轉屏幕導致去掉狀態(tài)欄失敗");  
    }  
    scrView.setDrawingCacheEnabled(false);  
    scrView.destroyDrawingCache();  
    return scrBmp;  
}

標簽: isp 代碼

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Java給定公歷日期計算相應農(nóng)歷/陰歷日期

下一篇:PHP模擬多線程請求代碼示例