android webview 截图快照
方法一:
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 ,