4

I'm trying to open URL in a WebView from a background service then take a screenshot of the hidden WebView.

Funnily enough it is not working! Is this possible? Some code snippets:

webView.setVisibility(View.INVISIBLE);
...
final Picture picture = webView.capturePicture();
final Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(b);
picture.draw(c);
....

Thanks

twiz911
  • 634
  • 1
  • 9
  • 18

1 Answers1

1

See my question Android: take a 'screenshot' of a web page from a background service?

You have to get your bitmap from the webview's drawing cache eg.

mWebView.setDrawingCacheEnabled(true);
Bitmap b = mWebView.getDrawingCache();

You also have to set the "size" of the WebView, so that it is not 0 x 0 size.

Community
  • 1
  • 1
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65