1. 只截取自己应用内部界面
1.1 只截取自己应用内部界面
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(dView.getDrawingCache());
if (bitmap != null) {
try {
// 获取内置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) {
}
}
1.2 截取某个控件或者区域
两种方案:
跟上面差不多,只不过view不适用根view,而是使用某个