简体   繁体   中英

Android Open WebView In Background Service And Capture Screen Shot

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM