初始化webview之前,不然截图只有当前显示的部分,其余为空白
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.webkit.WebView.enableSlowWholeDocumentDraw();
}
截图调用
private Bitmap captureWebViewLollipop() {
float scale = mWebView.getScale();
int width = mWebView.getWidth();
int height = (int) (mWebView.getContentHeight() * scale + 0.5);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
mWebView.draw(canvas);
return bitmap;
}
网友评论