【发布时间】:2021-07-13 02:58:11
【问题描述】:
我想将 Jetpack compose 发出的 UI 捕获为位图。在 XML 中是这样完成的:
基本上将视图作为输入参数并将其作为位图返回。
//take screenshot of the view added as an input argument
fun takeScreenShot(view: View) : Bitmap {
val bitmap = Bitmap.createBitmap(
view.width,
view.height,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
view.draw(canvas)
return bitmap
}
在 Jetpack compose 中相当于什么?
【问题讨论】:
-
另请参阅github.com/JohannBlake/bitmap-from-composable,以了解为此使用
ComposeView的示例。
标签: android android-jetpack-compose android-jetpack