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

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/media/ImageReader.Builder "View this page in Java")

```
class Builder
```

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

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

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#Builder(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)` Constructs a new builder for `https://developer.android.com/reference/kotlin/android/media/ImageReader`. |

| Public methods ||
|---|---|
| [ImageReader](https://developer.android.com/reference/kotlin/android/media/ImageReader) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#build()()` Builds a new ImageReader object. |
| [ImageReader.Builder](https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultDataSpace(kotlin.Int)(dataSpace: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the default dataspace passed by the producer. |
| [ImageReader.Builder](https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultHardwareBufferFormat(kotlin.Int)(hardwareBufferFormat: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the default hardwareBuffer format passed by the producer. |
| [ImageReader.Builder](https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setImageFormat(kotlin.Int)(imageFormat: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the default image format passed by the producer. |
| [ImageReader.Builder](https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setMaxImages(kotlin.Int)(maxImages: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the maximal number of images. |
| [ImageReader.Builder](https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#) | `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setUsage(kotlin.Long)(usage: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Set the consumer usage flag. |

## Public constructors

### Builder

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

```
Builder(
    width: Int, 
    height: Int)
```

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

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

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/Image`

## Public methods

### build

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

```
fun build(): ImageReader
```

Builds a new ImageReader object.

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

### setDefaultDataSpace

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

```
fun setDefaultDataSpace(dataSpace: Int): ImageReader.Builder
```

Set the default dataspace passed by the producer. May be overridden by the producer.

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

| Parameters ||
|---|---|
| `dataSpace` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The dataspace of the image that this reader will produce. The default value is `https://developer.android.com/reference/kotlin/android/hardware/DataSpace.html#DATASPACE_UNKNOWN:kotlin.Int`. 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/ImageReader.Builder#` | the builder instance with customized dataspace value. This value cannot be `null`. |

**See Also**

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

### setDefaultHardwareBufferFormat

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

```
fun setDefaultHardwareBufferFormat(hardwareBufferFormat: Int): ImageReader.Builder
```

Set the default hardwareBuffer format passed by the producer. May be overridden by the producer.

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

The format of the Image can be overridden after `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setImageFormat(kotlin.Int)` by calling this function and then `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultDataSpace(kotlin.Int)` functions. *Warning:* Missing one of callings for initializing or overriding the format may involve undefined behaviors.

| Parameters ||
|---|---|
| `hardwareBufferFormat` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The HardwareBuffer format of the image that this reader will produce. The default value is `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#RGBA_8888:kotlin.Int`. 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/ImageReader.Builder#` | the builder instance with customized hardwareBuffer value. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultDataSpace(kotlin.Int)`
- `https://developer.android.com/reference/kotlin/android/media/ImageReader.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): ImageReader.Builder
```

Set the default image format passed by the producer. May be overridden by the producer.

`https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setImageFormat(kotlin.Int)` function replaces the combination of `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultHardwareBufferFormat(kotlin.Int)` and `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultDataSpace(kotlin.Int)` functions. Either this or these two functions must be called to initialize an `ImageReader` instance.

| Parameters ||
|---|---|
| `imageFormat` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The format of the image that this reader will produce. This must be one of the `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#` or `https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#` constants. Note that not all formats are supported, like ImageFormat.NV21. The default value is `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#UNKNOWN:kotlin.Int`. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#UNKNOWN:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_8888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBX_8888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RGB_565:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YV12:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#Y8:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YCBCR_P010:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YCBCR_P210:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#NV16:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#NV21:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YUY2:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#JPEG:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#DEPTH_JPEG:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YUV_420_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YUV_422_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YUV_444_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#FLEX_RGB_888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#FLEX_RGBA_8888:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_PRIVATE:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW10:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW12:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW14:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#DEPTH16:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#DEPTH_POINT_CLOUD:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#PRIVATE:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#HEIC:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#HEIC_ULTRAHDR:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#JPEG_R:kotlin.Int` |

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

**See Also**

- `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultHardwareBufferFormat(kotlin.Int)`
- `https://developer.android.com/reference/kotlin/android/media/ImageReader.Builder#setDefaultDataSpace(kotlin.Int)`

### setMaxImages

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

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

Set the maximal number of images.

| 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. This should be as small as possible to limit memory use. Default value is 1. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/ImageReader.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): ImageReader.Builder
```

Set the consumer usage flag.

| Parameters ||
|---|---|
| `usage` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): The intended usage of the images consumed by this ImageReader. See the usages on `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#` for a list of valid usage bits. Default value is `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#USAGE_CPU_READ_OFTEN:kotlin.Long`. 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/ImageReader.Builder#` | the Builder instance with customized usage value. This value cannot be `null`. |

**See Also**

- `https://developer.android.com/reference/kotlin/android/hardware/HardwareBuffer.html#`