當(dāng)前位置:
首頁 >
原生WebView长截图 和 Tencent x5webview截长图
發(fā)布時間:2023/12/31
49
豆豆
生活随笔
收集整理的這篇文章主要介紹了
原生WebView长截图 和 Tencent x5webview截长图
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言: 之前項目用的是原生webview,最近使用公司新框架使用的是x5的webview;正好有需求需要做長截圖,踩坑之路開始。
1、原生WebView長截圖
Android5.0及以上版本,Android對WebView進行了優(yōu)化,為了減少內(nèi)存使用和提高性能,使用WebView加載網(wǎng)頁時只繪制顯示部分。如果我們不做處理,仍然使用上述代碼截圖的話,就會出現(xiàn)只截到屏幕內(nèi)顯示的WebView內(nèi)容,其它部分是空白的情況。
這時候,我們通過調(diào)用WebView.enableSlowWholeDocumentDraw()方法可以關(guān)閉這種優(yōu)化,但要注意的是,該方法需要在WebView實例被創(chuàng)建前就要調(diào)用,否則沒有效果。
2、Tencent x5webview截長圖
/*** Tencent x5webview截長圖** @param webView* @return*/public static Bitmap getX5WebViewBtpBase64Str(WebView webView) {if (webView == null) {return null;}int wholeWidth = webView.getContentWidth();int wholeHeight = webView.getContentHeight();Bitmap x5bitmap = Bitmap.createBitmap(wholeWidth, wholeHeight, Bitmap.Config.RGB_565);Canvas x5canvas = new Canvas(x5bitmap); // x5canvas.scale((float) wholeWidth / (float) webView.getContentWidth(), (float) wholeHeight / (float)webView.getContentHeight());if (webView.getX5WebViewExtension() == null) {return null;}IX5WebViewExtension ix5WebViewExtension = webView.getX5WebViewExtension();ix5WebViewExtension.snapshotWholePage(x5canvas, false, false);Bitmap bitmap = Bitmap.createBitmap(x5bitmap);return bitmap;}總結(jié)
以上是生活随笔為你收集整理的原生WebView长截图 和 Tencent x5webview截长图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python学习——格拉布斯准则实现
- 下一篇: 卷积码和Turbo码