I have a webview that I want to turn into a bitmap for another part of my application.
Currently, I can get a bitmap of the portion of the webview that will be rendered onscreen, however my bitmap needs to contain all of the page's contents.
Setting the webview's layoutParams to a larger size results in the original image loading onto a larger canvas.
Here is my current implementation:
FrameLayout.LayoutParams tempParams= new FrameLayout.LayoutParams(2000,4000);
_webView.setLayoutParams(tempParams);
_webView.layout(0,0,2000,4000);
int width = _webView.getWidth();
int height = _webView.getHeight();
_webView.postDelayed(new Runnable() {
@Override
public void run() {
Bitmap bitmap = Bitmap.createBitmap(_webView.getWidth(), _webView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
_webView.draw(canvas);
}
},100);
I have followed the following tutorials and they do not seem to resolve my issue.
Rendering Android webview to bitmap, html5 javascript , callback issue
Generate bitmap from HTML in Android
I was thinking about using a PictureListener and capturePicture() but those have been deprecated.