-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathPatchableToBitmap.kt
More file actions
59 lines (52 loc) · 1.87 KB
/
Copy pathPatchableToBitmap.kt
File metadata and controls
59 lines (52 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package de.berlindroid.zepatch.ui
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import de.berlindroid.zepatch.utils.CaptureToBitmap
/**
* Renders the provided [patchable] into a Bitmap-like [ImageBitmap] and displays it via [Image].
* Uses a composable utility that captures the composed content from a graphics layer.
*/
@Composable
fun PatchableToBitmap(
modifier: Modifier = Modifier,
onBitmap: (ImageBitmap) -> Unit = {},
patchable: @Composable () -> Unit,
) {
var image by remember { mutableStateOf<ImageBitmap?>(null) }
var capture by remember { mutableStateOf(false) }
Column(modifier = modifier.fillMaxWidth()) {
Button(onClick = {
image = null
capture = true
}) { Text("Do it") }
// Compose the content through the composable utility; it will invoke the callback when ready.
CaptureToBitmap(
modifier = Modifier.fillMaxWidth(),
capture = capture,
onBitmap = { img ->
image = img
capture = false
},
content = patchable
)
image?.let {
Image(
bitmap = it,
contentDescription = "patch bitmap",
modifier = Modifier.fillMaxWidth()
)
onBitmap(it)
} ?: CircularProgressIndicator()
}
}