Android截屏
Android截屏的原理:获取具体需要截屏的区域的Bitmap,然后绘制在画布上,保存为图片后进行分享或者其它用途
一、Activity截屏
1、截Activity界面(包含空白的状态栏)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
2、截Activity界面(去除状态栏)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
二、View截屏
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
三、ScrollView截屏:ScrollView只有一个childView,虽然没有全部显示在界面上,但是已经全部渲染绘制,因此可以直接 调用scrollView.draw(canvas)来完成截图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
四、ListView截屏:ListView是会回收与重用Item,并且只会绘制在屏幕上显示的ItemView,下面的方法采用一个List来存储Item的视图,这种方案依然不够好,当Item足够多的时候,可能会发生oom。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
五、RecycleView截屏
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
六、WebView截屏
1、截取webView可视区域的截图
1 2 3 4 5 6 7 8 9 |
|
2、截取webView的整个页面
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
3、截取手机屏幕,获取界面展示的webview
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|