how to use ResolutionSelector with ResolutionStrategy instead of setTargetResolution() in AndroidStudio?

1.5k Views Asked by At

First of all, I ask for your understanding of the rudimentary question.

I want to get image from camera input and analysis it. but I have a problem to set image resolution. What i know for set format of getting image is the 'ImageAnalysis.Build().setTargetResolution()' function that was deprecated... so I have to use ResolutionSelector with ResolutionStrategy. but I don't know how to use it. Since Analysis is another class, I can't use ResolutionSelector with declaration. And I can't find a way to connect the two.

As a result, what i want to know is other way to play the role of 'setTargetResolution()'.

what i tried for it is use ResolutionSelector.Build()'s method in ImageAnlysis.Build() but, naturally, impossible. and I tried to find way to use ResolutionSelctor. but i can't find what useful....

the reference link about setTargetSolution https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis.Builder

2

There are 2 best solutions below

0
On BEST ANSWER

There is a method setResolutionSelector() when you are building the use case.

So you would have ImageAnalysis.Builder().setResolutionSelector(*PUT SELECTOR HERE*).build()

0
On

Maybe this example will help you:

 val screenSize = if (rotation == 0) Size(720, 1280) else Size(1280, 720)
    val resolutionSelector = ResolutionSelector.Builder().setResolutionStrategy(ResolutionStrategy(screenSize,
        ResolutionStrategy.FALLBACK_RULE_NONE)).build()
    val preview = Preview.Builder()
        .setResolutionSelector(resolutionSelector)
        .build()