1

I'm setting the target resolution like below

var imageResolution = Size(480, 640)

imageCapture = ImageCapture.Builder()
               .setTargetResolution(imageResolution)
               .build()

Now, I need to change the resolution. So, I tried

var imageResolution = Size(1200, 1600)
imageCapture?.updateSuggestedResolution(imageResolution)

but, it is giving a error

error 1
UseCase.updateSuggestedResolution can only be called from within the same library group (groupId=androidx.camera) 


error 2
Photo capture failed: The completer object was garbage collected - this future would otherwise never complete. The tag was: issueTakePicture[stage=0]

I didn't able to figure it out when error 1 & 2 will occur and noticed that error 2 will not let the image to get saved.

And all images if taken and successfully saved the resolution was 1080*1080 only, If I have tried to change its resolution at least once. else, after ImageCapture.Builder() step If I didn't tried to change the resolution it would retain the resolution what I mentioned.

why it is coming and How to avoid this warning ?

Vikas Acharya
  • 3,550
  • 4
  • 19
  • 52
  • 1
    For error 1, as the message says, `updateSuggestedResolution()` shouldn't be called from anywhere outside the CameraX library. To update the resolution of a use case, you have to do so using `Builder.setTargetResolution()`. 480x640 is a common resolution and is supported on most devices I think, which is why it may have worked for you. Is 1200x1600 a supported image capture resolution on the device you're testing on? You can check the supported sizes using `StreamConfigurationMap#getOutputSizes(int)`. – Husayn Hakeem Nov 20 '20 at 20:16
  • @HusaynHakeem StreamConfigurationMap#getOutputSizes(int) how to use this ? No tutorial anywhere. – Vikas Acharya Nov 21 '20 at 05:37
  • @HusaynHakeem how to set setTargetResolution() without unbindall & rebinding ? This is causing screen to blink. – Vikas Acharya Nov 21 '20 at 05:39
  • Afaik, setting a new resolution means re-configuring the capture session, since a new surface with the new resolution would need to be passed to the camera. This means that the preview will probably glitch for a moment until the camera begins to provide frames with the new configuration. – Husayn Hakeem Nov 22 '20 at 00:35

1 Answers1

0

ok, I had the same issue today (Error 2). I was using an old way to manage onActivityResult (the depreciated way), after I receive the result, the app open de camera and it takes the picture. For some reason, if the camera is started after de activityResult it throws the garbage collected problem.

To solve that, I used the new way to manage the onActivityResult.

This links helped me:

OnActivityResult method is deprecated, what is the alternative?

https://developer.android.com/training/basics/intents/result#java

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 23:37