Android webview screenshot in case of hardware acceleration

Viewed 327

I want to get a screenshot of webview,and code show as follow:

View view = myWebView; Bitmap mBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mBitmap); view.draw(canvas);

It doesn‘t works under hardware acceleration(webView or activity set), when i turn off hardware acceleration, I can get a normal screenshot, otherwise it is a white screen。

test url is : http://cdn.codeboy.me/canvas.html

and then screen before hardware acceleration turn on:

and after hardware acceleration turn on:

Is any way to get webView's screenshot under hardware acceleration(just webView and not window or decorView), and anybody can explain why it doesn't work when turn on hardware acceleration.

1 Answers

I have got the same issue. My solution is using MediaProjection API to capture full screen image, then crop the image to get WebView's screenshot.

Related