How to use onDraw(Canvas) to obtain a bitmap snapshot of the WebView(Android)

不打扰是莪最后的温柔 提交于 2019-12-07 17:45:18

问题


I used to use capturePicture() method to make a snapshot of my WebView. This method was deprecated in API level 19.

The doc say that "Use onDraw(Canvas) to obtain a bitmap snapshot of the WebView", but I really don't know how it means.

Will you please teach me how to solve the problem?


回答1:


The following should work:

float scale = webView.getScale();
int webViewHeight = (int)(webView.getContentHeight() * scale);
Bitmap image = Bitmap.createBitmap(webView.getWidth(), webViewHeight, Config.ARGB_8888);
Canvas canvas = new Canvas(image);
webView.draw(canvas);


来源:https://stackoverflow.com/questions/19856832/how-to-use-ondrawcanvas-to-obtain-a-bitmap-snapshot-of-the-webviewandroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!