Capture webview's current display to bitmap
<p>I have a webview , which would be loaded with a large html file. The webview is scrollable, and the user is able to see the rest of the pages by scrolling it. As the user scrolls down the page, at some point of time I want to get a bitmap image of the webview ( currently what the user is seeing) , not the entire page's image. I know the webView.capturePicture() can create a picture , but it gives the entire webpage's image.
I tried the following code snippet, but it gives me the image of the starting-page of the html file, even if the user has scrolled down the page many times.</p>

<pre><code>    WebView webView = new WebView(getApplicationContext());

    webView.setVerticalScrollBarEnabled(true);
    webView.setHorizontalScrollBarEnabled(false);
    webView.getSettings().setBuiltInZoomControls(false);
    webView.getSettings().setUseWideViewPort(false);
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            //pageFinished = true;
        }
    });
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("file://"+Environment.getExternalStorageDirectory() + "/main.html");
</code></pre>

<p>In onClick() of a Button, I used the following code to get the snapshot of the webview:</p>

<pre><code>    try {
        Bitmap bitmap = Bitmap.createBitmap(webView.getWidth(), webView.getHeight(),
                Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);

            webView.draw(canvas);
            FileOutputStream out = new FileOutputStream(
                            Environment.getExternalStorageDirectory()
                                    + "/out.png");
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); // saving bitmap
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code></pre>

<p>Any help is appreciated.</p>

<p>Thanks in advance,
Suji</p>
