WebView截屏

来源:互联网 发布:js怎么判断是不是数组 编辑:程序博客网 时间:2024/06/05 04:54

WebView的截图有几种方式

(一)这种方式要求WebView必须设置setDrawingCacheEnabled(true)

 /**     * 这种方法要求webview要设置setDrawingCacheEnabled(true);     * @return     */    public Bitmap getWebViewFromCache(){        Bitmap drawingCacheBitmap = mWebView.getDrawingCache();        return drawingCacheBitmap;    }

(二)这种方式在安卓4.4已经废除,因为capturePicture方法废除了

public Bitmap getWebViewCapturePicture(){        Picture picture = mWebView.capturePicture();        Bitmap bitmap = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);        Canvas canvas = new Canvas(bitmap);        mWebView.draw(canvas);        return bitmap;    }

(三)直接给当前页面截屏

/**     * 截屏     * @return     */    public Bitmap getWebViewDecorView(){        View decorView = this.getWindow().getDecorView();        Bitmap bitmap = Bitmap.createBitmap(decorView.getWidth(), decorView.getHeight(), Bitmap.Config.ARGB_8888);        Canvas canvas = new Canvas(bitmap);        decorView.draw(canvas);        return bitmap;    }


0 0
原创粉丝点击