# AvifWriter.Builder

Artifact: [androidx.heifwriter:heifwriter](https://developer.android.com/jetpack/androidx/releases/heifwriter) [View Source](https://cs.android.com/search?q=file:androidx/heifwriter/AvifWriter.java+class:androidx.heifwriter.AvifWriter.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/heifwriter#1.1.0)

*** ** * ** ***


```
class AvifWriter.Builder
```

<br />

*** ** * ** ***

Builder class for constructing a AvifWriter object from specified parameters.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#Builder(java.io.FileDescriptor,int,int,int)( fd: https://developer.android.com/reference/java/io/FileDescriptor.html, width: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, inputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Construct a Builder with output specified by its file descriptor. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#Builder(java.lang.String,int,int,int)( path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, width: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, inputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Construct a Builder with output specified by its path. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#build()()` Build a AvifWriter object. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setEncoderPreference(androidx.heifwriter.EncoderPreference)(preference: https://developer.android.com/reference/kotlin/androidx/heifwriter/EncoderPreference)` Sets the encoder preference for this builder. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setGridEnabled(boolean)(gridEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Set whether to enable grid option. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setHandler(android.os.Handler)(handler: https://developer.android.com/reference/android/os/Handler.html?)` Provide a handler for the AvifWriter to use. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setHighBitDepthEnabled(boolean)(highBitDepthEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Provide a setting for the AvifWriter to use high bit-depth or not. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setMaxImages(int)(maxImages: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the maximum number of images to write. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setPrimaryIndex(int)(primaryIndex: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the primary image index. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setQuality(int)(quality: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the quality for encoding images. |
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder#setRotation(int)(rotation: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the image rotation in degrees. |

## Public constructors

### Builder

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

```
Builder(
    fd: FileDescriptor,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)
```

Construct a Builder with output specified by its file descriptor.

| Parameters |
|---|---|
| `fd: https://developer.android.com/reference/java/io/FileDescriptor.html` | File descriptor of the file to be written. |
| `width: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Width of the image in number of pixels. |
| `height: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Height of the image in number of pixels. |
| `inputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Input mode for this writer, must be one of `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_BUFFER()`, `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_SURFACE()`, or `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_BITMAP()`. |

### Builder

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

```
Builder(
    path: String,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)
```

Construct a Builder with output specified by its path.

| Parameters |
|---|---|
| `path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Path of the file to be written. |
| `width: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Width of the image in number of pixels. |
| `height: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Height of the image in number of pixels. |
| `inputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Input mode for this writer, must be one of `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_BUFFER()`, `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_SURFACE()`, or `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_BITMAP()`. |

## Public functions

### build

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

```
fun build(): AvifWriter
```

Build a AvifWriter object.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter` | a AvifWriter object built according to the specifications. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if failed to create the writer, possibly due to failure to create `https://developer.android.com/reference/android/media/MediaMuxer.html` or `https://developer.android.com/reference/android/media/MediaCodec.html`. |

### setEncoderPreference

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

```
fun setEncoderPreference(preference: EncoderPreference): AvifWriter.Builder
```

Sets the encoder preference for this builder.

This method allows you to configure the desired encoding type (hardware or software) and the bitrate mode (e.g., constant quality).

| Parameters |
|---|---|
| `preference: https://developer.android.com/reference/kotlin/androidx/heifwriter/EncoderPreference` | The non-null `https://developer.android.com/reference/kotlin/androidx/heifwriter/EncoderPreference` object used to specify the encoder's configuration. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | This `Builder` instance for method chaining. |

### setGridEnabled

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

```
fun setGridEnabled(gridEnabled: Boolean): AvifWriter.Builder
```

Set whether to enable grid option.

| Parameters |
|---|---|
| `gridEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to enable grid option. If enabled, the tile size will be automatically chosen. Default is to enable. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setHandler

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

```
fun setHandler(handler: Handler?): AvifWriter.Builder
```

Provide a handler for the AvifWriter to use.

| Parameters |
|---|---|
| `handler: https://developer.android.com/reference/android/os/Handler.html?` | If not null, client will receive all callbacks on the handler's looper. Otherwise, client will receive callbacks on a looper created by the writer. Default is null. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setHighBitDepthEnabled

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

```
fun setHighBitDepthEnabled(highBitDepthEnabled: Boolean): AvifWriter.Builder
```

Provide a setting for the AvifWriter to use high bit-depth or not.

| Parameters |
|---|---|
| `highBitDepthEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to enable high bit-depth mode. Default is false, if true, AvifWriter will encode with high bit-depth. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setMaxImages

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

```
fun setMaxImages(maxImages: @IntRange(from = 1) Int): AvifWriter.Builder
```

Set the maximum number of images to write.

| Parameters |
|---|---|
| `maxImages: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Max number of images to write. Frames exceeding this number will not be written to file. The writing can be stopped earlier before this number of images are written by `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#stop(long)`, except for the input mode of `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#INPUT_MODE_SURFACE()`, where the EOS timestamp must be specified (via `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter#setInputEndOfStreamTimestamp(long)` and reached. Default is 1. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setPrimaryIndex

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

```
fun setPrimaryIndex(primaryIndex: @IntRange(from = 0) Int): AvifWriter.Builder
```

Set the primary image index.

| Parameters |
|---|---|
| `primaryIndex: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Index of the image that should be marked as primary, must be within range \[0, maxImages - 1\] inclusive. Default is 0. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setQuality

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

```
fun setQuality(quality: @IntRange(from = 0, to = 100) Int): AvifWriter.Builder
```

Set the quality for encoding images.

| Parameters |
|---|---|
| `quality: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A number between 0 and 100 (inclusive), with 100 indicating the best quality supported by this implementation. Default is 100. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |

### setRotation

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

```
fun setRotation(rotation: @IntRange(from = 0) Int): AvifWriter.Builder
```

Set the image rotation in degrees.

| Parameters |
|---|---|
| `rotation: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Rotation angle in degrees (clockwise) of the image, must be 0, 90, 180 or 270. Default is 0. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/heifwriter/AvifWriter.Builder` | this Builder object. |