Android Webview仅从页面顶部获取屏幕截图 [英] Android webview takes screenshot only from top of the page

查看:374
本文介绍了Android Webview仅从页面顶部获取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个非常简单的任务,将我的webView的屏幕截图捕获到位图中……我这样做是这样的:

I am doing a very simple task of taking a screenshot from my webView into a Bitmap... I do it like this:

webView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(webView.getDrawingCache(false));
webView.setDrawingCacheEnabled(false);
Canvas canvas = new Canvas(bitmap);
webView.draw(canvas);

问题在于最终的位图总是显示我网页内容的顶部!我实际上需要它来从滚动内容的地方截取屏幕截图,但这不是简单的事情!我已经在网上搜索了两个小时,但是似乎没有其他人遇到类似的问题.知道可能出了什么问题吗?

The problem is that the final bitmap is always showing the top of my web page content! I actually need it to take the screenshot from where I have scrolled the content but this is not simply happening! I have been searching the net for two hours now but no one else seems to have a similar problem. any idea what could have gone wrong?

推荐答案

我猜是在棒棒糖上吗?如果是这样,请确保调用WebView.enableSlowWholeDocumentDraw()( doc ),则在首次调用setContentView()时,该调用会使用WebView扩大布局.

I guess, this is on Lollipop? If so, make sure you call WebView.enableSlowWholeDocumentDraw() (doc) before your first call to setContentView() that inflates a layout with WebView.

这篇关于Android Webview仅从页面顶部获取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆