How to properly replace the deprecated setTargetResolution method?

82 views Asked by At

I opened one of my old pet projects. There's CameraX lib. Everything's fine. But setTargetResolution has been depricated. Deprecated use ResolutionSelector with ResolutionStrategy to specify the preferred resolution settings instead.

It would seem that me just need to replace, as written in the tooltip, with:

.setResolutionSelector(
   ResolutionSelector.Builder()
     .setResolutionStrategy(

Some troubles.

If in setTargetResolution the size selection was

if (this.resources.configuration.orientation ==
      Configuration.ORIENTATION_PORTRAIT)
          Size(height, width)
else
          Size(width,height)

Then in setResolutionStrategy I had to change to

if (this.resources.configuration.orientation ==
      Configuration.ORIENTATION_LANDSCAPE)

And after that, if everything is fine at small resolutions, then at 4000x3000 the error is:

Java.lang.IllegalArgumentException: No supported surface combination is found for camera device - Id : 0. May be attempting to bind too many use cases.

How to properly replace the deprecated setTargetResolution method?

0

There are 0 answers