# Palette.Builder

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

*** ** * ** ***


```
class Palette.Builder
```

<br />

*** ** * ** ***

Builder class for generating `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#Builder(android.graphics.Bitmap)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html)` Construct a new `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` using a source `https://developer.android.com/reference/android/graphics/Bitmap.html` |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#Builder(java.util.List<androidx.palette.graphics.Palette.Swatch>)(swatches: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Swatch!>)` Construct a new `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` using a list of `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Swatch` instances. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#addFilter(androidx.palette.graphics.Palette.Filter)(filter: https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Filter)` Add a filter to be able to have fine grained control over which colors are allowed in the resulting palette. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#addTarget(androidx.palette.graphics.Target)(target: https://developer.android.com/reference/kotlin/androidx/palette/graphics/Target)` Add a target profile to be generated in the palette. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#clearFilters()()` Clear all added filters. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#clearRegion()()` Clear any previously region set via `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#setRegion(int,int,int,int)`. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#clearTargets()()` Clear all added targets. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#generate()()` Generate and return the `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette` synchronously. |
| `https://developer.android.com/reference/android/os/AsyncTask.html<https://developer.android.com/reference/android/graphics/Bitmap.html!, https://developer.android.com/reference/java/lang/Void.html!, https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette!>` | `[generate](https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#generate(androidx.palette.graphics.Palette.PaletteAsyncListener))(listener: https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.PaletteAsyncListener)` **This function is deprecated.** Use the standard `java.util.concurrent` or [Kotlin concurrency utilities](https://developer.android.com/topic/libraries/architecture/coroutines) to call `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#generate()` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#maximumColorCount(int)(colors: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the maximum number of colors to use in the quantization step when using a `https://developer.android.com/reference/android/graphics/Bitmap.html` as the source. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#resizeBitmapArea(int)(area: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the resize value when using a `https://developer.android.com/reference/android/graphics/Bitmap.html` as the source. |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `[resizeBitmapSize](https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#resizeBitmapSize(int))(maxDimension: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Using `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#resizeBitmapArea(int)` is preferred since it can handle abnormal aspect ratios more gracefully. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` | `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#setRegion(int,int,int,int)(left: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set a region of the bitmap to be used exclusively when calculating the palette. |

## Public constructors

### Builder

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

```
Builder(bitmap: Bitmap)
```

Construct a new `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` using a source `https://developer.android.com/reference/android/graphics/Bitmap.html`

### Builder

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

```
Builder(swatches: (Mutable)List<Palette.Swatch!>)
```

Construct a new `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder` using a list of `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Swatch` instances. Typically only used for testing.

## Public functions

### addFilter

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

```
fun addFilter(filter: Palette.Filter): Palette.Builder
```

Add a filter to be able to have fine grained control over which colors are allowed in the resulting palette.

| Parameters |
|---|---|
| `filter: https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Filter` | filter to add. |

### addTarget

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

```
fun addTarget(target: Target): Palette.Builder
```

Add a target profile to be generated in the palette.

You can retrieve the result via `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette#getSwatchForTarget(androidx.palette.graphics.Target)`.

### clearFilters

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

```
fun clearFilters(): Palette.Builder
```

Clear all added filters. This includes any default filters added automatically by `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette`.

### clearRegion

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

```
fun clearRegion(): Palette.Builder
```

Clear any previously region set via `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#setRegion(int,int,int,int)`.

### clearTargets

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

```
fun clearTargets(): Palette.Builder
```

Clear all added targets. This includes any default targets added automatically by `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette`.

### generate

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

```
fun generate(): Palette
```

Generate and return the `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette` synchronously.

### generate

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

```
fun [generate](https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#generate(androidx.palette.graphics.Palette.PaletteAsyncListener))(listener: Palette.PaletteAsyncListener): AsyncTask<Bitmap!, Void!, Palette!>
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use the standard `java.util.concurrent` or [Kotlin concurrency utilities](https://developer.android.com/topic/libraries/architecture/coroutines) to call `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#generate()` instead.

Generate the `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette` asynchronously. The provided listener's `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.PaletteAsyncListener#onGenerated(androidx.palette.graphics.Palette)` method will be called with the palette when generated.

### maximumColorCount

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

```
fun maximumColorCount(colors: Int): Palette.Builder
```

Set the maximum number of colors to use in the quantization step when using a `https://developer.android.com/reference/android/graphics/Bitmap.html` as the source.

Good values for depend on the source image type. For landscapes, good values are in the range 10-16. For images which are largely made up of people's faces then this value should be increased to \~24.

### resizeBitmapArea

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

```
fun resizeBitmapArea(area: Int): Palette.Builder
```

Set the resize value when using a `https://developer.android.com/reference/android/graphics/Bitmap.html` as the source. If the bitmap's area is greater than the value specified, then the bitmap will be resized so that its area matches `area`. If the bitmap is smaller or equal, the original is used as-is.

This value has a large effect on the processing time. The larger the resized image is, the greater time it will take to generate the palette. The smaller the image is, the more detail is lost in the resulting image and thus less precision for color selection.

| Parameters |
|---|---|
| `area: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the number of pixels that the intermediary scaled down Bitmap should cover, or any value \<= 0 to disable resizing. |

### resizeBitmapSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/palette#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/palette#1.0.0)

```
fun [resizeBitmapSize](https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#resizeBitmapSize(int))(maxDimension: Int): Palette.Builder
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Using `https://developer.android.com/reference/kotlin/androidx/palette/graphics/Palette.Builder#resizeBitmapArea(int)` is preferred since it can handle abnormal aspect ratios more gracefully.

Set the resize value when using a `https://developer.android.com/reference/android/graphics/Bitmap.html` as the source. If the bitmap's largest dimension is greater than the value specified, then the bitmap will be resized so that its largest dimension matches `maxDimension`. If the bitmap is smaller or equal, the original is used as-is.

| Parameters |
|---|---|
| `maxDimension: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the number of pixels that the max dimension should be scaled down to, or any value \<= 0 to disable resizing. |

### setRegion

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

```
fun setRegion(left: @Px Int, top: @Px Int, right: @Px Int, bottom: @Px Int): Palette.Builder
```

Set a region of the bitmap to be used exclusively when calculating the palette.

This only works when the original input is a `https://developer.android.com/reference/android/graphics/Bitmap.html`.

| Parameters |
|---|---|
| `left: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The left side of the rectangle used for the region. |
| `top: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The top of the rectangle used for the region. |
| `right: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The right side of the rectangle used for the region. |
| `bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The bottom of the rectangle used for the region. |