我对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像素的图像。我的网页相当大(高度约为2000px)。我已经尝试了不同的方法来解决这个问题,但仍然没有重复。
答案 0 :(得分:1)
我找到了解决方案。
如果您遇到同样的问题,可以将onPicture Listener添加到您的网页视图中,如下所示
web.setPictureListener(new WebView.PictureListener() {
public void onNewPicture(WebView view, Picture picture) {
float temp = (float) view.getHeight();
height = view.getContentHeight() * a;
}
});
并获得所有需要的高度和宽度
答案 1 :(得分:0)
为了拍摄webview的图片你必须启用缓存,你可以从缓存中获取它作为位图,下面我提到代码希望对你有用 -
webview.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
它正在为我工作只是检查你的身边,将等你接受answer.thanks