I am doing a very simple task of taking a screenshot from my webView into a Bitmap... I do it like this:
webView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(webView.getDrawingCache(false));
webView.setDrawingCacheEnabled(false);
Canvas canvas = new Canvas(bitmap);
webView.draw(canvas);
The problem is that the final bitmap is always showing the top of my web page content! I actually need it to take the screenshot from where I have scrolled the content but this is not simply happening! I have been searching the net for two hours now but no one else seems to have a similar problem. any idea what could have gone wrong?
Use the usual button combination (Power + Volume down) to capture a screenshot. On the bottom left corner, you'll see a thumbnail of your screenshot with a button below it called Long Screenshot. Tap on it. Scroll down on the page till you reach your desired point and hit Save.
On Android, start by tapping the 'V' icon at the top of the screen and select “Capture page”. Then choose whether you want to take a full page screenshot, or just capture the “Visible Area” (which is, a screenshot of what you can currently see on your screen). The image will be saved to your device.
JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.
I guess, this is on Lollipop? If so, make sure you call WebView.enableSlowWholeDocumentDraw() (doc) before your first call to setContentView()
that inflates a layout with WebView.
Actually, you don't need the last 2 lines.Just drop them.
webView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(webView.getDrawingCache(false));
webView.setDrawingCacheEnabled(false);
will return the very bitmap you need, from what I've seen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With