Android獲取webView快照與屏幕截屏的方法
不用多說,你懂得! 直接上代碼:
/** * 截取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; }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!