# ResolutionSelector

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/resolutionselector/ResolutionSelector.java+class:androidx.camera.core.resolutionselector.ResolutionSelector) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

*** ** * ** ***


```
class ResolutionSelector
```

<br />

*** ** * ** ***

A set of requirements and priorities used to select a resolution for the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`.

The resolution selection mechanism is determined by the following three steps:

1. Collect the supported output sizes and add them to the candidate resolution list.
2. Filter and sort the candidate resolution list according to the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder` resolution settings.
3. Consider all the resolution selector settings of bound `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s to find the resolution that best suits each `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`.

For the first step, all supported resolution output sizes are added to the candidate resolution list as the starting point.

ResolutionSelector provides the following function for applications to adjust the candidate resolution settings.

- `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder#setAllowedResolutionMode(int)`

For the second step, ResolutionSelector provides the following three functions for applications to determine which resolution should be selected with higher priority.

- `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder#setAspectRatioStrategy(androidx.camera.core.resolutionselector.AspectRatioStrategy)`
- `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder#setResolutionStrategy(androidx.camera.core.resolutionselector.ResolutionStrategy)`
- `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder#setResolutionFilter(androidx.camera.core.resolutionselector.ResolutionFilter)`

CameraX sorts the collected sizes according to the specified aspect ratio and resolution strategies. The aspect ratio strategy has precedence over the resolution strategy for sorting the resolution candidate list. If applications specify a custom resolution filter, CameraX passes the resulting sizes list, sorted by the specified aspect ratio and resolution strategies, to the resolution filter to get the final desired list.

Different types of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s might have their own default settings. You can see the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` builders' `setResolutionSelector()` function to know the details for each type of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`.

In the third step, CameraX selects the final resolution for the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` based on the camera device's hardware level, capabilities, and the bound `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` combination. Applications can check which resolution is finally selected by using the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`'s `getResolutionInfo()` function.

Note that a ResolutionSelector with more restricted settings may result in that no resolution can be selected to use. Applications will receive `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` when binding the `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s with such kind of ResolutionSelector. Applications can specify the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy` and `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy` with proper fallback rules to avoid the `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` or try-catch it and show a proper message to the end users.

When creating a ResolutionSelector instance, the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#RATIO_4_3_FALLBACK_AUTO_STRATEGY()` will be the default `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy` if it is not set. `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#PREFER_CAPTURE_RATE_OVER_HIGHER_RESOLUTION()` is the default allowed resolution mode. However, if neither the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy` nor the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionFilter` are set, there will be no default value specified.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector.Builder` Builder for a `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector`. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#PREFER_CAPTURE_RATE_OVER_HIGHER_RESOLUTION() = 0` This mode allows CameraX to select the normal output sizes on the camera device. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#PREFER_HIGHER_RESOLUTION_OVER_CAPTURE_RATE() = 1` This mode allows CameraX to select the output sizes which might result in slower capture times. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#getAllowedResolutionMode()()` Returns the specified allowed resolution mode. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#getAspectRatioStrategy()()` Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy`, or `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#RATIO_4_3_FALLBACK_AUTO_STRATEGY()` if none is specified when creating the ResolutionSelector. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionFilter?` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#getResolutionFilter()()` Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionFilter` implementation, or null if not specified. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy?` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector#getResolutionStrategy()()` Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy`, or null if not specified. |

## Constants

### PREFER_CAPTURE_RATE_OVER_HIGHER_RESOLUTION

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
const val PREFER_CAPTURE_RATE_OVER_HIGHER_RESOLUTION = 0: Int
```

This mode allows CameraX to select the normal output sizes on the camera device.

The available resolutions for this mode are obtained from the `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getOutputSizes(int)` method from the stream configuration map obtained with the `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SCALER_STREAM_CONFIGURATION_MAP` camera characteristics.

### PREFER_HIGHER_RESOLUTION_OVER_CAPTURE_RATE

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
const val PREFER_HIGHER_RESOLUTION_OVER_CAPTURE_RATE = 1: Int
```

This mode allows CameraX to select the output sizes which might result in slower capture times.

The available resolutions for this mode are obtained from the `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getOutputSizes(int)` and `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getHighResolutionOutputSizes(int)` methods from the stream configuration map obtained with the `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SCALER_STREAM_CONFIGURATION_MAP` camera characteristics. However, please note that using a resolution obtained from the `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getHighResolutionOutputSizes(int)` may result in slower capture times. Please see the javadoc of `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getHighResolutionOutputSizes(int)` for more details.

Since Android 12, some devices might support a maximum resolution sensor pixel mode, which allows them to capture additional ultra high resolutions retrieved from `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SCALER_STREAM_CONFIGURATION_MAP_MAXIMUM_RESOLUTION` . This mode does not allow applications to select those ultra high resolutions.

## Public functions

### getAllowedResolutionMode

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun getAllowedResolutionMode(): Int
```

Returns the specified allowed resolution mode.

### getAspectRatioStrategy

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun getAspectRatioStrategy(): AspectRatioStrategy
```

Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy`, or `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#RATIO_4_3_FALLBACK_AUTO_STRATEGY()` if none is specified when creating the ResolutionSelector.

### getResolutionFilter

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun getResolutionFilter(): ResolutionFilter?
```

Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionFilter` implementation, or null if not specified.

### getResolutionStrategy

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
fun getResolutionStrategy(): ResolutionStrategy?
```

Returns the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy`, or null if not specified.