/**
* 截屏
*/
private Bitmap screenShots() {
//获取当前屏幕的大小
int width = getWindow().getDecorView().getRootView().getWidth();
int height = getWindow().getDecorView().getRootView().getHeight();
//找到当前页面的跟布局
View view = getWindow().getDecorView().getRootView();
//设置缓存
view.setDrawingCacheEnabled(false);
view.buildDrawingCache();
//从缓存中获取当前屏幕的图片
Bitmap temBitmap = view.getDrawingCache();
//生成相同大小的图片
Bitmap bitmap = Bitmap.createBitmap(temBitmap, 0, 0, width, height);
view.destroyDrawingCache();//不清空,第二次截屏则使用的是缓存的同一张。
return bitmap;
}
Android截屏,无需权限。
最新推荐文章于 2023-04-08 15:59:45 发布