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