android屏幕截图代码,android中实现整个屏幕截图的代码
android開發中實現整個屏幕截圖,首先通過activity對象的getwindow()方法獲得整個屏幕的window對象,再通過整個屏幕的window對象的getDecorView()方法獲得整個屏幕的view,最后截圖的實現,也就是將view轉換成bitmap,然后,將bitmap保存為圖片文件。
android中實現整個屏幕截圖的代碼
public static Bitmap takeScreenShot(Activity act) {
if (act == null || act.isFinishing()) {
Log.d(TAG, "act參數為空.");
return null;
}
// 獲取當前視圖的view
View scrView = act.getWindow().getDecorView();
scrView.setDrawingCacheEnabled(true);
scrView.buildDrawingCache(true);
// 獲取狀態欄高度
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("", "#### 旋轉屏幕導致去掉狀態欄失敗");
}
scrView.setDrawingCacheEnabled(false);
scrView.destroyDrawingCache();
return scrBmp;
}
版權申明:本站文章部分自網絡,如有侵權,請聯系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯系。
總結
以上是生活随笔為你收集整理的android屏幕截图代码,android中实现整个屏幕截图的代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】[iOS] 关于 self = [
- 下一篇: Android的Fragment介绍