Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Android CameraX: java.lang.IllegalStateException: maxImages (2) has already been acquired, call #close before acquiring more

Posted on November 11, 2022 By

Solution 1 :

The super.onCaptureSuccess(image) should be at the beginning of the onCaptureSuccess function. You call super.onCaptureSuccess(image) after closing the image.

Solution 2 :

analyzing super.onCaptureSuccess(image); he calls image.close(), so you call close twice, try remove super from onCaptureSuccess method

Problem :

Whenever a second picture is taken getting this particular error:

    D/CaptureSession: Issuing capture request.
W/ImageReader_JNI: Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers
D/MetadataImageReader: Failed to acquire next image.
    java.lang.IllegalStateException: maxImages (2) has already been acquired, call #close before acquiring more.
        at android.media.ImageReader.acquireNextImage(ImageReader.java:513)
        at androidx.camera.core.AndroidImageReaderProxy.acquireNextImage(AndroidImageReaderProxy.java:79)
        at androidx.camera.core.MetadataImageReader.imageIncoming(MetadataImageReader.java:318)
        at androidx.camera.core.MetadataImageReader$2.onImageAvailable(MetadataImageReader.java:67)
        at androidx.camera.core.AndroidImageReaderProxy$1$1.run(AndroidImageReaderProxy.java:145)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7814)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

As per my understand we have to close the image before clicking the next one but I have even done that, still getting the same error

Here is my code:

    private void takePicture()  {
    imageCapture.setFlashMode(flashMode);
    imageCapture.takePicture(cameraExecutor, new ImageCapture.OnImageCapturedCallback() {
        @SuppressLint("UnsafeExperimentalUsageError")
        @Override
        public void onCaptureSuccess(@NonNull ImageProxy image) {
            Bitmap imageBitmap = rotateImage(imageToBitmap(Objects.requireNonNull(image.getImage())), image.getImageInfo().getRotationDegrees());
            try {
                FileUtil.saveBitmap(MainActivity.this, imageBitmap);

            } catch (IOException e) {
                e.printStackTrace();
            }
            image.close();
            super.onCaptureSuccess(image);
        }
        @Override
        public void onError(@NonNull ImageCaptureException exception) {
            super.onError(exception);
        }
    });
}

As seen in the code, I’m closing the image. Still, it did not solve the issue.

Answers such as:
Android camera2: java.lang.IllegalStateException: maxImages (1) has already been acquired, call #close before acquiring more

Suggested to close the image in ImageReader.OnImageAvailableListener, but through CameraX we are not directly dealing with ImageReader.

Please suggest a method to resolve this issue.

Comments

Comment posted by Husayn Hakeem

If you empty the

Comment posted by Prajwal Bhat

@HusaynHakeem, Yes, with just image.close() also the issue is still there when taking multiple pictures

READ  [FIXED] Creating a Search Interface -Android
Powered by Inline Related Posts

Comment posted by Prajwal Bhat

@HusaynHakeem, Any suggestions?

Comment posted by Husayn Hakeem

This seems like a weird bug. a) Do you have your code somewhere I can pull it and test it? (on github for instance). b) Could you update to beta05 (which was released today), and verify if the issue still occurs.

Comment posted by Husayn Hakeem

Testing your code, it seems the app doesn’t crash due to that exception. By clicking on the image capture button multiple times, all images are taken successfully. Is that the behavior you’re also seeing? As for the exception stacktrace being displayed in the logcat, it’s thrown internally by CameraX. The image capture use case handles a pipeline on incoming capture requests, and only takes 1 picture at a time. I’m guessing this stacktrace can be ignored if your app isn’t crashing and the pictures are being stored successfully. You can also create an issue and file it to CameraX.

Comment posted by Prajwal Bhat

Yes, onCaptureSuccess(image); method does close the image. But removing that didn’t solve the issue.

Android Tags:android, android-camerax

Post navigation

Previous Post: [FIXED] Android Studios error : Unable to locate adb location
Next Post: [FIXED] android – Here Maps Navigation samples seem to be missing the Navigation Library

Related Posts

[FIXED] android – Not able to hit perl end point from retrofit2 Android
[FIXED] android – The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant) Android
[FIXED] java – How to put many recyclerview in a fragment Android
[FIXED] android – Undefined name ‘_LoginController’ Flutter – Dart Android
[FIXED] kotlin – Not sure where to autogenerate Primary Keys in Room Android
[FIXED] Unexpected behaviour of MediaPlayer Android Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme