使用 Kotlin 将视图保存到位图而不在 Android 中显示它

问题描述 投票:0回答:1

我们如何使用 Kotlin 将视图保存到位图而不在 Android 中显示它

之前我们用过

 View.setDrawingCacheEnabled(true);
 Bitmap bmp=  View.getDrawingCache(); 

但现在

getDrawingCache
已被弃用

我们如何保存视图而不显示它。

android kotlin android-bitmap
1个回答
0
投票

在我的解决方案中,在 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)
}
© www.soinside.com 2019 - 2024. All rights reserved.