
Captures screenshots of composables and Android Views. Experimental, supports rendering composables into images, and converting views to bitmaps for versatile UI testing and documentation.
You probably no longer need this library (or similar libraries) because Jetpack Compose and Compose Multiplatform now support taking screenshots. See Jetpack Compose take screenshot of composable function.
Multiplatform library to take/capture screenshot/snapshot/picture/image of @Composables (and also Android Views).
🚧 This library is experimental and tested only on Windows and Android.
🚧 This library may not be suited for use in production code.
implementation("ir.mahozad.multiplatform:comshot:0.3.0")@Composables)captureToImage. Also, it should be called from the Main aka UI thread (see its KDoc for more information).
@Composable
fun Activity.MyComposable() {
val activity = this
var screenshot by remember { mutableStateOf<ImageBitmap?>(null) }
val composable: @Composable () -> Unit = remember {
@Composable {
Row {
Text(text = "Hello")
Text(text = "Meow!")
}
}
}
// You can also render your composable simply like this:
// composable()
Column {
Button(onClick = { screenshot = captureToImage(activity, composable) }) {
Text(text = "Capture")
}
screenshot?.let {
Image(
bitmap = it,
modifier = Modifier.width(200.dp),
contentDescription = null
)
}
}
}Views)
val view = findViewById<TextView>(R.id.myTextView)
val screenshot = captureToImage(view)
// If you want Bitmap:
val androidBitmap = screenshot.asAndroidBitmap()@Composable
fun MyComposable() {
var screenshot by remember { mutableStateOf<ImageBitmap?>(null) }
val composable: @Composable () -> Unit = remember {
@Composable {
Row {
Text(text = "Hello")
Text(text = "Meow!")
}
}
}
// You can also render your composable simply like this:
// composable()
Column {
Button(onClick = { screenshot = captureToImage(composable) }) {
Text(text = "Capture")
}
screenshot?.let {
Image(
bitmap = it,
modifier = Modifier.width(200.dp),
contentDescription = null
)
}
}
}You probably no longer need this library (or similar libraries) because Jetpack Compose and Compose Multiplatform now support taking screenshots. See Jetpack Compose take screenshot of composable function.
Multiplatform library to take/capture screenshot/snapshot/picture/image of @Composables (and also Android Views).
🚧 This library is experimental and tested only on Windows and Android.
🚧 This library may not be suited for use in production code.
implementation("ir.mahozad.multiplatform:comshot:0.3.0")@Composables)captureToImage. Also, it should be called from the Main aka UI thread (see its KDoc for more information).
@Composable
fun Activity.MyComposable() {
val activity = this
var screenshot by remember { mutableStateOf<ImageBitmap?>(null) }
val composable: @Composable () -> Unit = remember {
@Composable {
Row {
Text(text = "Hello")
Text(text = "Meow!")
}
}
}
// You can also render your composable simply like this:
// composable()
Column {
Button(onClick = { screenshot = captureToImage(activity, composable) }) {
Text(text = "Capture")
}
screenshot?.let {
Image(
bitmap = it,
modifier = Modifier.width(200.dp),
contentDescription = null
)
}
}
}Views)
val view = findViewById<TextView>(R.id.myTextView)
val screenshot = captureToImage(view)
// If you want Bitmap:
val androidBitmap = screenshot.asAndroidBitmap()@Composable
fun MyComposable() {
var screenshot by remember { mutableStateOf<ImageBitmap?>(null) }
val composable: @Composable () -> Unit = remember {
@Composable {
Row {
Text(text = "Hello")
Text(text = "Meow!")
}
}
}
// You can also render your composable simply like this:
// composable()
Column {
Button(onClick = { screenshot = captureToImage(composable) }) {
Text(text = "Capture")
}
screenshot?.let {
Image(
bitmap = it,
modifier = Modifier.width(200.dp),
contentDescription = null
)
}
}
}