//这种方法状态栏是空白,显示不了状态栏的信息
private void saveCurrentImage() {
//获取当前屏幕的大小
int width = getWindow().getDecorView().getRootView().getWidth();
int height = getWindow().getDecorView().getRootView().getHeight();
//生成相同大小的图片
Bitmap temBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//找到当前页面的根布局
View view = getWindow().getDecorView().getRootView();
//设置缓存
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
//从缓存中获取当前屏幕的图片,创建一个DrawingCache的拷贝,因为DrawingCache得到的位图在禁用后会被回收
temBitmap = view.getDrawingCache();
SimpleDateFormat df = new SimpleDateFormat("yyyymmddhhmmss");
time = df.format(new Date());
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/youImageName", time + ".png");
if (!file.exists()) {
file.getParentFile().mkdirs();
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
temBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//禁用DrawingCahce否则会影响性能 ,而且不禁止会导致每次截图到保存的是第一次截图缓存的位图
view.setDrawingCacheEnabled(false);
}
}
屏幕截图
原创
©著作权归作者所有:来自51CTO博客作者mp624183768的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:php mysql一些简单操作
下一篇:已解决|php insert into 插入失败 |Incorrect string value: '\xE5\x88\x98\xE5\xAE\x89' for column 'name
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java|屏幕截图
欢迎点击「算法与编程之美」↑关注我们!本文首发于:"算法与编程之美",欢迎关注,及时了解更多此系列文章。欢迎加入团队圈子!与作者面对面!直接点击!1 前言初入j...
游戏 javascript html nagios cakephp -
C# 屏幕截图
C# 屏幕截图
C# 屏幕截图 System Windows Linq -
Java屏幕截图工具 捕获屏幕
原文:http://www.open-open.com/code/view/1420037709781
java 工具类 支付宝 释放资源 屏幕截图