Heim > Fragen und Antworten > Hauptteil
private void screenshot1(String Strname)
{
/**
* Strname--如 2.png 需要带后缀
* */
// 获取屏幕
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bmp = dView.getDrawingCache();
if (bmp != null)
{
try {
// 获取内置SD卡路径
String sdCardPath = Environment.getExternalStorageDirectory().getPath();
// 图片文件路径
File filedir = new File(sdCardPath + File.separator + "AA"); // 这里的AA为创建的AA文件夹,在根目录下
if (!filedir.exists()) {
filedir.mkdirs();
}
File saveFile = new File(filedir, Strname);
FileOutputStream outStream1 = new FileOutputStream(saveFile);
System.out.println(outStream1.toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
outStream1.write(byteArray);
outStream1.close();
Toast.makeText(Zhuye_Activity.this,"截图保存成功",Toast.LENGTH_SHORT).show();
dView.setDrawingCacheEnabled(false); // 这里不设置false,那么下次截图还是上次的图片
} catch (Exception e) {
}
}
}
这个方不行……谁有解决方法?
高洛峰2017-04-18 09:07:42
github 传送门: jraska/Falcon: Take Android screenshots with Falcons bright eye!
p.s. 这个解决方式也不完美, 底部导航的按钮没截进图.