close image after capturing as Bitmap

This commit is contained in:
darthpaul 2022-10-05 13:09:21 +01:00
parent 2627638a76
commit 315f8f559c
1 changed files with 12 additions and 6 deletions

View File

@ -441,12 +441,18 @@ class CameraXPreview(
if (mediaOutput is MediaOutput.BitmapOutput) {
imageCapture.takePicture(mainExecutor, object : OnImageCapturedCallback() {
override fun onCaptureSuccess(image: ImageProxy) {
listener.toggleBottomButtons(false)
val bitmap = BitmapUtils.makeBitmap(image.toJpegByteArray())
if (bitmap != null) {
listener.onImageCaptured(bitmap)
} else {
cameraErrorHandler.handleImageCaptureError(ERROR_CAPTURE_FAILED)
ensureBackgroundThread {
image.use {
val bitmap = BitmapUtils.makeBitmap(image.toJpegByteArray())
activity.runOnUiThread {
listener.toggleBottomButtons(false)
if (bitmap != null) {
listener.onImageCaptured(bitmap)
} else {
cameraErrorHandler.handleImageCaptureError(ERROR_CAPTURE_FAILED)
}
}
}
}
}