本文介紹了Android 實現(xiàn)截屏方式整理,分享給大家。希望對大家有幫助
可能的需求:
1.只截取自己應(yīng)用內(nèi)部界面
1.1 截取除了導(dǎo)航欄之外的屏幕
View dView = getWindow().getDecorView(); dView.setDrawingCacheEnabled(true); dView.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(dView.getDrawingCache()); if (bitmap != null) { try { // 獲取內(nèi)置SD卡路徑 String sdCardPath = Environment.getExternalStorageDirectory().getPath(); // 圖片文件路徑 String filePath = sdCardPath + File.separator + "screenshot.png"; File file = new File(filePath); FileOutputStream os = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); os.flush(); os.close(); DebugLog.d("a7888", "存儲完成"); } catch (Exception e) { } }