gpt4 book ai didi

java - WebView 内容大小

转载 作者:行者123 更新时间:2023-11-30 03:57:28 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com