Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.media.ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) |

Builder class for `https://developer.android.com/reference/kotlin/android/media/ImageWriter` objects.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#Builder(android.view.Surface)(surface: https://developer.android.com/reference/kotlin/android/view/Surface.html#)` Constructs a new builder for `https://developer.android.com/reference/kotlin/android/media/ImageWriter`. |

| Public methods ||
|---|---|
| [ImageWriter](https://developer.android.com/reference/kotlin/android/media/ImageWriter) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#build()()` Builds a new ImageWriter object. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setDataSpace(kotlin.Int)(dataSpace: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the dataspace of this ImageWriter. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setHardwareBufferFormat(kotlin.Int)(hardwareBufferFormat: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the hardwareBuffer format of this ImageWriter. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setImageFormat(kotlin.Int)(imageFormat: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the image format of this ImageWriter. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setMaxImages(kotlin.Int)(maxImages: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the maximum number of images. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setUsage(kotlin.Long)(usage: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Set the usage flag of this ImageWriter. |
| [ImageWriter.Builder](https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setWidthAndHeight(kotlin.Int,%20kotlin.Int)(width: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the width and height of images. |

## Public constructors

### Builder

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder(surface: Surface)
```

Constructs a new builder for `https://developer.android.com/reference/kotlin/android/media/ImageWriter`.

| Parameters ||
|---|---|
| `surface` | [Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#): The destination Surface this writer produces Image data into. This value cannot be `null`. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if the surface is already abandoned. |

## Public methods

### build

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): ImageWriter
```

Builds a new ImageWriter object.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter` | The new ImageWriter object. This value cannot be `null`. |

### setDataSpace

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setDataSpace(dataSpace: Int): ImageWriter.Builder
```

Set the dataspace of this ImageWriter. The default value is `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_UNKNOWN:kotlin.Int`.

| Parameters ||
|---|---|
| `dataSpace` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The dataspace of the image that this writer will produce. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_DEPTH:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_DYNAMIC_DEPTH:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_HEIF:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_HEIF_ULTRAHDR:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_JPEG_R:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_UNKNOWN:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_SCRGB_LINEAR:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_SRGB:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_SCRGB:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_DISPLAY_P3:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT2020_HLG:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT2020_PQ:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_ADOBE_RGB:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_JFIF:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT601_625:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT601_525:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT2020:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_BT709:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_DCI_P3:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_SRGB_LINEAR:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_DISPLAY_BT2020:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the builder instance with customized dataspace value. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setHardwareBufferFormat(kotlin.Int)`

### setHardwareBufferFormat

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setHardwareBufferFormat(hardwareBufferFormat: Int): ImageWriter.Builder
```

Set the hardwareBuffer format of this ImageWriter. The default value is `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_8888:kotlin.Int`.

This function works together with `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setDataSpace(kotlin.Int)` for an `https://developer.android.com/reference/kotlin/android/media/ImageWriter` instance. Setting at least one of these two replaces `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setImageFormat(kotlin.Int)` function.

| Parameters ||
|---|---|
| `hardwareBufferFormat` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The HardwareBuffer format of the image that this writer will produce. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_8888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_FP16:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_1010102:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBX_8888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGB_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGB_565:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#BLOB:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#YCBCR_420_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#D_16:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#D_24:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#DS_24UI8:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#D_FP32:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#DS_FP32UI8:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#S_UI8:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#YCBCR_P010:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#YCBCR_P210:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#R_8:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#R_16:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RG_1616:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_10101010:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#R_12:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#R_14:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RG_1212:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RG_1414:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_12121212:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_14141414:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#BGRA_1010102:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#BGRX_1010102:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the Builder instance with customized buffer format. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setDataSpace(kotlin.Int)`
- `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#setImageFormat(kotlin.Int)`

### setImageFormat

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setImageFormat(imageFormat: Int): ImageWriter.Builder
```

Set the image format of this ImageWriter. Default format depends on the Surface provided.

| Parameters ||
|---|---|
| `imageFormat` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The format of the `https://developer.android.com/reference/kotlin/android/media/ImageWriter`. It can be any valid specified by `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#` or `https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the Builder instance with customized image format. This value cannot be `null`. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if `imageFormat` is invalid. |

### setMaxImages

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setMaxImages(maxImages: Int): ImageWriter.Builder
```

Set the maximum number of images. Default value is 1.

| Parameters ||
|---|---|
| `maxImages` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The maximum number of Images the user will want to access simultaneously for producing Image data. Value is 1 or greater |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the Builder instance with customized usage value. This value cannot be `null`. |

### setUsage

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setUsage(usage: Long): ImageWriter.Builder
```

Set the usage flag of this ImageWriter.

If this function is not called, usage bit will be set to `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_WRITE_OFTEN:kotlin.Long` if the image format is not `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#PRIVATE:kotlin.Int`.

| Parameters ||
|---|---|
| `usage` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): The intended usage of the images produced by this ImageWriter. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_READ_RARELY:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_READ_OFTEN:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_WRITE_RARELY:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_WRITE_OFTEN:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_GPU_SAMPLED_IMAGE:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_GPU_COLOR_OUTPUT:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_COMPOSER_OVERLAY:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_PROTECTED_CONTENT:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_VIDEO_ENCODE:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_GPU_DATA_BUFFER:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_SENSOR_DIRECT_DATA:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_GPU_CUBE_MAP:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_GPU_MIPMAP_COMPLETE:kotlin.Long` - `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_FRONT_BUFFER:kotlin.Long` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the Builder instance with customized usage flag. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#`
- `https://developer.android.com/reference/kotlin/android/media/ImageWriter#getUsage()`

### setWidthAndHeight

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setWidthAndHeight(
    width: Int, 
    height: Int
): ImageWriter.Builder
```

Set the width and height of images. Default size is dependent on the Surface that is provided by the downstream end-point.

| Parameters ||
|---|---|
| `width` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The width in pixels that will be passed to the producer. Value is 1 or greater |
| `height` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The height in pixels that will be passed to the producer. Value is 1 or greater |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageWriter.Builder#` | the Builder instance with customized width and height. This value cannot be `null`. |