简体   繁体   English

Android打开WebView在后台服务和捕获屏幕射击

[英]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. 我正在尝试从后台服务打开WebView中的URL,然后截取隐藏的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? 看我的问题Android:从后台服务中获取网页的“屏幕截图”?

You have to get your bitmap from the webview's drawing cache eg. 您必须从webview的绘图缓存中获取位图,例如。

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. 您还必须设置WebView的“大小”,以使其不是0 x 0大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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