我在 webview 内容大小方面遇到了一些问题。我需要将整个网页转换为单个图像并尝试使用此代码
Bitmap screenshot;
screenshot = Bitmap.createBitmap(view.getWidth(), view.getContentHeight(), Bitmap.Config.ARGB_8888);
final Canvas c =new Canvas(screenshot);
view.draw(c);
其中“ View ”是一个 WebView 对象
但结果是一张具有 1024x769 像素的图像。我的网页相当大(高度约为 2000 像素)。我尝试了不同的方法来解决这个问题,但结果仍然为零。
最佳答案
我找到了解决方案。
如果你有同样的问题,你可以在你的webview中添加onPicture Listener,像这样
web.setPictureListener(new WebView.PictureListener() {
public void onNewPicture(WebView view, Picture picture) {
float temp = (float) view.getHeight();
height = view.getContentHeight() * a;
}
});
得到所有你需要的高度和宽度
关于java - WebView 内容大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13120138/