android webview 截图快照
16lz
2021-12-20
方法一:
Picture snapShot = view.capturePicture();
if (snapShot.getWidth() > 0 && snapShot.getHeight() > 0) {
Bitmap b = Bitmap.createBitmap(snapShot.getWidth(),
snapShot.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
snapShot.draw(c);
Bitmap newBitmap = zoomBitmap(b, 250, 250);
historyModel.setSnapshot(newBitmap);
方法二(经过测试,平板竖屏是经常截图失败, 原因是root.getDrawingCache()尺寸超过限制):
View root = activity.getWindow().getDecorView();
private Bitmap catchScreen(View root) {
root.setDrawingCacheEnabled(true);
root.setDrawingCacheBackgroundColor(0);
root.buildDrawingCache(true);
Bitmap b = root.getDrawingCache();
return b;
}
方法三(成功率高):
// create snapshot for webview
View cv = activity.getWindow().getDecorView();
Bitmap b = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),
Config.ARGB_4444);
cv.draw(new Canvas(b));
更多相关文章
- 阅读《Android(安卓)从入门到精通》(12)——自动完成文本框
- android内部类广播(本地广播)BroadcastReceiver的静态注册方法(Andr
- Android弹出对话框简单代码
- android 图文列表的实现方法
- 使用universal-image-loader中出现的EOFException解决方法
- Android(安卓)关闭所有Activity完全退出程序方法
- Android(安卓)ListView列表分组
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用