Android获取webView快照与屏幕截屏的方法
jopen
11年前
不用多说,你懂得! 直接上代码:
/** * 截取webView可视区域的截图 * @param webView 前提:WebView要设置webView.setDrawingCacheEnabled(true); * @return */ private Bitmap captureWebViewVisibleSize(WebView webView){ Bitmap bmp = webView.getDrawingCache(); return bmp; }
只截取屏幕中显示出来部分的webView画面:
/** * 截取webView快照(webView加载的整个内容的大小) * @param webView * @return */ private Bitmap captureWebView(WebView webView){ Picture snapShot = webView.capturePicture(); Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); return bmp; }
截取webView的整个页面:
/** * 截屏 * @param context * @return */ private Bitmap captureScreen(Activity context){ View cv = context.getWindow().getDecorView(); Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),Config.ARGB_8888); Canvas canvas = new Canvas(bmp); cv.draw(canvas); return bmp; }