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.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
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
|
||||
private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: MutableState<Offset>) {
|
||||
cameraUiState.captureState.processedImage?.let { image ->
|
||||
private fun CapturedImage(image: ImageBitmap, thumbnailCoords: MutableState<Offset>) {
|
||||
Surface(
|
||||
color = Color.Black.copy(alpha = 0.3f),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -217,7 +219,8 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
||||
label = "scale"
|
||||
) { if (it) 0.3f else 1f }
|
||||
|
||||
Box (modifier = Modifier
|
||||
Box (contentAlignment = Alignment.BottomStart,
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.8f)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
val bounds = coordinates.boundsInWindow()
|
||||
@@ -230,7 +233,7 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
||||
}
|
||||
) {
|
||||
Image(
|
||||
bitmap = image.asImageBitmap(),
|
||||
bitmap = image,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -243,7 +246,6 @@ private fun CapturedImage(cameraUiState: CameraUiState, thumbnailCoords: Mutable
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
Reference in New Issue
Block a user