Avoid calling Bitmap.asImageBitmap() too often
This commit is contained in:
@@ -61,6 +61,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.layout.boundsInWindow
|
import androidx.compose.ui.layout.boundsInWindow
|
||||||
@@ -182,13 +183,14 @@ private fun CameraScreenScaffold(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CapturedImage(cameraUiState, thumbnailCoords)
|
cameraUiState.captureState.processedImage?.let {
|
||||||
|
image -> CapturedImage(image.asImageBitmap(), thumbnailCoords)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: MutableState<Offset>) {
|
private fun CapturedImage(image: ImageBitmap, thumbnailCoords: MutableState<Offset>) {
|
||||||
cameraUiState.captureState.processedImage?.let { image ->
|
|
||||||
Surface(
|
Surface(
|
||||||
color = Color.Black.copy(alpha = 0.3f),
|
color = Color.Black.copy(alpha = 0.3f),
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@@ -217,7 +219,8 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
|||||||
label = "scale"
|
label = "scale"
|
||||||
) { if (it) 0.3f else 1f }
|
) { if (it) 0.3f else 1f }
|
||||||
|
|
||||||
Box (modifier = Modifier
|
Box (contentAlignment = Alignment.BottomStart,
|
||||||
|
modifier = Modifier
|
||||||
.fillMaxHeight(0.8f)
|
.fillMaxHeight(0.8f)
|
||||||
.onGloballyPositioned { coordinates ->
|
.onGloballyPositioned { coordinates ->
|
||||||
val bounds = coordinates.boundsInWindow()
|
val bounds = coordinates.boundsInWindow()
|
||||||
@@ -230,7 +233,7 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
bitmap = image.asImageBitmap(),
|
bitmap = image,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@@ -244,7 +247,6 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CaptureButton(onClick: () -> Unit, modifier: Modifier) {
|
fun CaptureButton(onClick: () -> Unit, modifier: Modifier) {
|
||||||
|
|||||||
Reference in New Issue
Block a user