2012-10-29 157 views
1

我在webview内容大小上遇到了一些问题。我需要整个网页转换成一个单一的形象,并试图将此代码WebView内容大小

Bitmap screenshot;     
screenshot = Bitmap.createBitmap(view.getWidth(), view.getContentHeight(), Bitmap.Config.ARGB_8888); 
final Canvas c =new Canvas(screenshot); 
view.draw(c); 

其中,“意见”是的WebView对象

但结果是,具有1024x769像素的图像。我的网页相当大(高度约为2000px)。我试过不同的方法来解决这个问题,但仍然没有rezult。

回答

0

连续服用,你必须启用缓存和从缓存中的网页流量的图片,你可以把它作为一个位图,下面我我提的代码希望你 -

webview.setDrawingCacheEnabled(true); 
    Bitmap bitmap = Bitmap.createBitmap(webview.getDrawingCache()); 
    webview.setDrawingCacheEnabled(false); 

这是为我工作会很有用只是检查你的身边,会等你接受答案。谢谢

+0

Undortunally,它的工作原理不正确。它只显示页面的顶部。 – user1059786

+0

你没有得到完整的页面? – Ravi

1

我找到解决办法。

如果你有同样的问题,你可以添加onPicture监听到的网页视图,这样

web.setPictureListener(new WebView.PictureListener() { 

     public void onNewPicture(WebView view, Picture picture) { 
      float temp = (float) view.getHeight(); 
      height = view.getContentHeight() * a; 
     } 

    }); 

,让你所有的需要的高度和宽度