Android webView 截屏

2017-12-08  本文已影响0人  滴沥的雨云

解决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;
    }


上一篇下一篇

猜你喜欢

热点阅读