# CompositionSettings

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

*** ** * ** ***


```
class CompositionSettings
```

<br />

*** ** * ** ***

Composition settings for dual concurrent camera. It includes alpha value for blending, offset in x, y coordinates, scale of width and height, and styling options like rounded corners and borders. The offset, and scale of width and height are specified in normalized device coordinates(NDCs). The offset is applied after scale. The origin of normalized device coordinates is at the center of the viewing volume. The positive X-axis extends to the right, the positive Y-axis extends upwards.The x, y values range from -1 to 1. E.g. scale with `(0.5f, 0.5f)` and offset with `(0.5f, 0.5f)` is the bottom-right quadrant of the output device.

Styling options like rounded corner ratio and border width ratio are normalized from 0 to 1, where a ratio of 1 is relative to half of the smaller dimension of the frame.

Composited dual camera frames preview and recording can be supported using `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings` and `https://developer.android.com/reference/kotlin/androidx/camera/core/ConcurrentCamera.SingleCameraConfig`. The z-order of composition is determined by the order of camera configs to bind. Currently the background color will be black by default. The resolution of camera frames for preview and recording will be determined by resolution selection strategy configured for each use case and the scale of width and height set in `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings`, so it is recommended to use 16:9 aspect ratio strategy for preview if 16:9 quality selector is configured for video capture. The mirroring and rotation of the camera frame will be applied after composition because both cameras are using the same use cases.

The following code snippet demonstrates how to display in Picture-in-Picture mode:

```kotlin
                       16
        ---
        |               c0             |
        |                              |
        |                              |
        |                              |
        |  ---                   |  9
        |  |       |                   |
        |  |   c1  |                   |
        |  |       |                   |
        |  ---                   |
        ---
        c0: primary camera
        c1: secondary camera
    
              ResolutionSelector resolutionSelector = new ResolutionSelector.Builder()
                .setAspectRatioStrategy(
                        AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY)
                .build();
        Preview preview = new Preview.Builder()
                .setResolutionSelector(resolutionSelector)
                .build();
        preview.setSurfaceProvider(mSinglePreviewView.getSurfaceProvider());
        UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
                .addUseCase(preview)
                .addUseCase(mVideoCapture)
                .build();
        SingleCameraConfig primary = new SingleCameraConfig(
                cameraSelectorPrimary,
                useCaseGroup,
                new CompositionSettings.Builder()
                        .setAlpha(1.0f)
                        .setOffset(0.0f, 0.0f)
                        .setScale(1.0f, 1.0f)
                        .build(),
                lifecycleOwner);
        SingleCameraConfig secondary = new SingleCameraConfig(
                cameraSelectorSecondary,
                useCaseGroup,
                new CompositionSettings.Builder()
                        .setAlpha(1.0f)
                        .setOffset(-0.3f, -0.4f)
                        .setScale(0.3f, 0.3f)
                        .build(),
                lifecycleOwner);
        cameraProvider.bindToLifecycle(ImmutableList.of(primary, secondary));
    
```

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings.Builder` A builder for `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings` instances. |

| ### Constants |
|---|---|
| `const https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings!` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#DEFAULT()` Default composition settings, which will display in full screen with no offset and scale. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getAlpha()()` Gets the alpha. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getBorderColor()()` Gets the border color. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0, to = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getBorderWidthRatio()()` Gets the border width as a normalized ratio from 0 to 1. |
| `https://developer.android.com/reference/kotlin/androidx/core/util/Pair<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getOffset()()` Gets the offset. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0, to = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getRoundedCornerRatio()()` Gets the rounded corner ratio. |
| `https://developer.android.com/reference/kotlin/androidx/core/util/Pair<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getScale()()` Gets the scale. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getZOrder()()` Gets the z-order. |

## Constants

### DEFAULT

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

```
const val DEFAULT: CompositionSettings!
```

Default composition settings, which will display in full screen with no offset and scale.

## Public functions

### getAlpha

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

```
fun getAlpha(): Float
```

Gets the alpha.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | alpha value. |

### getBorderColor

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

```
fun getBorderColor(): @ColorInt Int
```

Gets the border color.

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | border color value. |

### getBorderWidthRatio

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

```
fun getBorderWidthRatio(): @FloatRange(from = 0, to = 1) Float
```

Gets the border width as a normalized ratio from 0 to 1.

0 means no border. 1 means the border width equals half of the smaller dimension of the frame, which causes the borders to meet at the center and fill the smaller dimension. The ratio is relative to half of the smaller dimension of the frame, consistent with `https://developer.android.com/reference/kotlin/androidx/camera/core/CompositionSettings#getRoundedCornerRatio()`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0, to = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | border width ratio value. |

### getOffset

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

```
fun getOffset(): Pair<Float!, Float!>
```

Gets the offset.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/util/Pair<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!>` | offset value. |

### getRoundedCornerRatio

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

```
fun getRoundedCornerRatio(): @FloatRange(from = 0, to = 1) Float
```

Gets the rounded corner ratio.

The value is normalized from 0 to 1. 0 means no rounding (sharp corners). 1 means fully rounded (the radius of the rounded corners equals half of the smaller dimension of the frame, making the frame a circle if it's square, or pill-shaped if it's rectangular).

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0, to = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | rounded corner ratio value. |

### getScale

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

```
fun getScale(): Pair<Float!, Float!>
```

Gets the scale. Negative value means mirroring in X or Y direction.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/util/Pair<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!>` | scale value. |

### getZOrder

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

```
fun getZOrder(): @IntRange(from = 0) Int
```

Gets the z-order.

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | z-order value. |