I've tried to find a better solution for create bitmap from WebView content, but I can't find a approach. I did try following this solution, and it works, however, some methods are deprecated like webView.setDrawingCacheEnabled(true)
and webView.buildDrawingCache()
. Is there any better solution to achieve it?
My second approach is to use webView.draw(canvas)
like below, but it doesn't save the whole page WebView Content.
web.measure(View.MeasureSpec.makeMeasureSpec(
View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
web.layout(0, 0, web.measuredWidth,
web.measuredHeight)
val bitmap = Bitmap.createBitmap(web.measuredWidth, web.measuredHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
web.draw(canvas)