我们如何使用 Kotlin 将视图保存到位图而不在 Android 中显示它
之前我们用过
View.setDrawingCacheEnabled(true);
Bitmap bmp= View.getDrawingCache();
但现在
getDrawingCache
已被弃用
我们如何保存视图而不显示它。
在我的解决方案中,在 Android 9 和 10 上,我正在准备一个屏幕外的 WebView,加载 html 并将结果保存到位图。
// height and width should be >0
val myBitmap = Bitmap.createBitmap(
myView.measuredWidth,
myView.measuredHeight,
Bitmap.Config.ARGB_8888
)
myBitmap.applyCanvas {
myView.draw(this)
}