android Tencent x5webview截长图
生活随笔
收集整理的這篇文章主要介紹了
android Tencent x5webview截长图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發中遇到一個問題,截取屏幕作為一張圖片保存下來,測試的時候用的是大屏手機,一屏就能把內容全部顯示出來,但是用戶使用的是小屏手機,保存圖片之后發現屏幕外的內容截取不到,然后就是一頓百度
參考鏈接:WebView截取長圖
這種方式雖然可以截取長圖,但是保存之后的圖片會變得模糊,不建議使用
還有另外一種方式也可以做參考:webView及ScrollView長截圖
但是這是方式適合原生的webview截圖,不適合x5內核的webview截圖
不啰嗦了,直接上解決方式(源碼)
private Bitmap captureWebView(WebView webView) {int wholeWidth = webView.computeHorizontalScrollRange(); int wholeHeight = webView.computeVerticalScrollRange(); Bitmap x5bitmap = Bitmap.createBitmap(wholeWidth , wholeHeight, Bitmap.Config.ARGB_8888);Canvas x5canvas = new Canvas(x5bitmap); x5canvas.scale((float) wholeWidth / (float) webView.getContentWidth(), (float) wholeHeight / (float)webView.getContentHeight()); if ( webView.getX5WebViewExtension() == null) { return null; }webView.getX5WebViewExtension().snapshotWholePage(x5canvas, false, false); return x5bitmap; //保存自己實現吧 }總結
以上是生活随笔為你收集整理的android Tencent x5webview截长图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android ndk webview,
- 下一篇: oracle索引有哪些分类,Oracle