I am using CameraX
Here is my image capture :
mImageCapture = ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetAspectRatio(screenAspectRatio)
.build()
ImageCaptureListener :
mImageCapture.takePicture(
executor!!,
object : ImageCapture.OnImageCapturedCallback() {
override fun onCaptureSuccess(image: ImageProxy) {
Log.d("AAAA", "Success")
val rotatedBitmap = bitmapHelper.rotateImage(
bitmapHelper.imageToBitmap(image = image.image!!),
image.imageInfo.rotationDegrees.toFloat()
)
runOnUiThread {
mImageView.setImageBitmap(rotatedBitmap)
}
}
override fun onError(
imageCaptureError: Int,
message: String,
cause: Throwable?
) {
2
super.onError(imageCaptureError, message, cause)
}
})
When i call takePicture
app freezes, and only after 3-4 seconds onCaptureSuccess called
How can I make this process faster?
CameraX take photo slow because of compressing into JPEG.
The difference between MINIMIZE_LATENCY_MODE
and MAXIMIZE_QUALITY_MODE
is the JPEG image compression quality.
private static final byte JPEG_QUALITY_MAXIMIZE_QUALITY_MODE = 100;
private static final byte JPEG_QUALITY_MINIMIZE_LATENCY_MODE = 95;
Therefore, even if the MINIMIZE_LATENCY_MODE
mode is set, the image quality will only decrease from 100 to 95. Not much difference.
From the Version 1.1.0-alpha11, the API provides an additional function setJpegQuality
that allows to customize the compression quality. Can improve the delay when taking pictures.
If you don't care about the best image quality, you can use this method.
imageCapture = ImageCapture.Builder()
.setJpegQuality(QUALITY_JPEG_75)
.build()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With