7

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?

4
  • I think you need call image.close(). Try it, before runOnUiThread Apr 14, 2020 at 2:12
  • 1
    Hey @Rasul did you ever able to find out why it was slow. I mean I don't have anything like file operations and still only cameraX is taking about 1.5 seconds
    – AJay
    Aug 22, 2020 at 6:23
  • 1
    Hello Rasul Agakishiyev, have you found solution for this problem? Could you share it to me or people in need?
    – TaQuangTu
    Oct 9, 2020 at 6:45
  • I think that in your case rotating the bitmap is causing the delay
    – kostik
    Jul 20, 2021 at 7:31

3 Answers 3

1

I was comparing this solution with the freeze view solution described in stackoverflow and the second one is faster than getting the image with OnImageCapturedCallback. This is an example of how to freeze the screen and show the ImageProxy using ImageAnalysis, check the following example github

4
1

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()
0

You no need to use ImageAnalysis usecase because CameraX already supported get bitmap from previewView

See more detail here: https://developer.android.com/reference/androidx/camera/view/PreviewView#getBitmap()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.