解决5.0+上,截取的快照只显示了webview中显示出来的那部分,没有显示出来的部分是空白的。
Bitmap getViewBitmap(WebView webView){
int height = (int) (webView.getContentHeight() * webView.getScale());
int width = webView.getWidth();
int pH = webView.getHeight();
Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bm);
int top = height;
while (top > 0) {
if (top < pH) {
top = 0;
} else {
top -= pH;
}
canvas.save();
canvas.clipRect(0, top, width, top + pH);
webView.scrollTo(0, top);
webView.draw(canvas);
canvas.restore();
}
return bm;
}