# AspectRatioStrategy

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/AspectRatioStrategy.java+class:androidx.camera.core.resolutionselector.AspectRatioStrategy) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

*** ** * ** ***


```
class AspectRatioStrategy
```

<br />

*** ** * ** ***

The aspect ratio strategy defines the sequence of aspect ratios that are used to select the best size for a particular image.

Applications can create a `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector` with a proper AspectRatioStrategy to choose a resolution that matches the preferred aspect ratio.

By default, CameraX supports the common 4:3 and 16:9 aspect ratio settings. Some devices may offer additional output sizes. To access these, you'll need to create a `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector` with a `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionFilter` to find and select those specific sizes.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO() = 1` CameraX automatically chooses the next best aspect ratio which contains the closest field of view (FOV) of the camera sensor, from the remaining options. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_NONE() = 0` CameraX doesn't fall back to select sizes of any other aspect ratio when this fallback rule is used. |
| `const https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#RATIO_16_9_FALLBACK_AUTO_STRATEGY()` The pre-defined aspect ratio strategy that selects sizes with `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_16_9()` in priority. |
| `const https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#RATIO_4_3_FALLBACK_AUTO_STRATEGY()` The pre-defined default aspect ratio strategy that selects sizes with `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_4_3()` in priority. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#AspectRatioStrategy(int,int)(preferredAspectRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, fallbackRule: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a new AspectRatioStrategy instance, configured with the specified preferred aspect ratio and fallback rule. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#getFallbackRule()()` Returns the specified fallback rule for choosing the aspect ratio when the preferred aspect ratio is not available. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#getPreferredAspectRatio()()` Returns the specified preferred aspect ratio. |

## Constants

### FALLBACK_RULE_AUTO

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

```
const val FALLBACK_RULE_AUTO = 1: Int
```

CameraX automatically chooses the next best aspect ratio which contains the closest field of view (FOV) of the camera sensor, from the remaining options.

### FALLBACK_RULE_NONE

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

```
const val FALLBACK_RULE_NONE = 0: Int
```

CameraX doesn't fall back to select sizes of any other aspect ratio when this fallback rule is used.

Note that an AspectRatioStrategy 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 AspectRatioStrategy.

### RATIO_16_9_FALLBACK_AUTO_STRATEGY

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

```
const val RATIO_16_9_FALLBACK_AUTO_STRATEGY: AspectRatioStrategy
```

The pre-defined aspect ratio strategy that selects sizes with `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_16_9()` in priority. Then, selects sizes with other aspect ratios according to which aspect ratio can contain the closest FOV of the camera sensor.

Please see the [Output streams, Cropping, and Zoom](https://source.android.com/docs/core/camera/camera3_crop_reprocess) introduction to know more about the camera FOV.

### RATIO_4_3_FALLBACK_AUTO_STRATEGY

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

```
const val RATIO_4_3_FALLBACK_AUTO_STRATEGY: AspectRatioStrategy
```

The pre-defined default aspect ratio strategy that selects sizes with `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_4_3()` in priority. Then, selects sizes with other aspect ratios according to which aspect ratio can contain the closest FOV of the camera sensor.

Please see the [Output streams, Cropping, and Zoom](https://source.android.com/docs/core/camera/camera3_crop_reprocess) introduction to know more about the camera FOV.

## Public constructors

### AspectRatioStrategy

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

```
AspectRatioStrategy(preferredAspectRatio: Int, fallbackRule: Int)
```

Creates a new AspectRatioStrategy instance, configured with the specified preferred aspect ratio and fallback rule.

OEMs might make the width or height of the supported output sizes be mod 16 aligned for performance reasons. This means that the device might support 1920x1088 instead of 1920x1080, even though a 16:9 aspect ratio size is 1920x1080. CameraX can select these mod 16 aligned sizes when applications specify the preferred aspect ratio as `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_16_9()`.

Some devices may have issues using sizes of the preferred aspect ratios. CameraX recommends that applications use the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO()` setting to avoid no resolution being available, as an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` may be thrown when calling `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,androidx.camera.core.UseCase...)` to bind `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase`s with the AspectRatioStrategy specified in the `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionSelector`.

| Parameters |
|---|---|
| `preferredAspectRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the preferred aspect ratio to select first which can be either `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_4_3()` or `https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio#RATIO_16_9()`. |
| `fallbackRule: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the rule to follow when the preferred aspect ratio is unavailable. This can be either `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO()` or `https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_NONE()`. |

## Public functions

### getFallbackRule

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

```
fun getFallbackRule(): Int
```

Returns the specified fallback rule for choosing the aspect ratio when the preferred aspect ratio is not available.

### getPreferredAspectRatio

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

```
fun getPreferredAspectRatio(): Int
```

Returns the specified preferred aspect ratio.