Builder

class Builder
kotlin.Any
   ↳ androidx.palette.graphics.Palette.Builder

Builder class for generating Palette instances.

Summary

Public constructors
<init>(bitmap: Bitmap)

Construct a new Builder using a source Bitmap

Construct a new Builder using a list of Swatch instances.

Public methods
Palette.Builder
addTarget(target: Target)

Add a target profile to be generated in the palette.

Palette.Builder

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

Palette.Builder
resizeBitmapSize(maxDimension: Int)

Set the resize value when using a android.graphics.Bitmap as the source.

Palette.Builder

Clear all added targets.

Palette.Builder

Set the resize value when using a android.graphics.Bitmap as the source.

Palette.Builder

Clear any previously region set via #setRegion(int, int, int, int).

Palette.Builder

Clear all added filters.

Palette.Builder
setRegion(left: Int, top: Int, right: Int, bottom: Int)

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

Palette

Generate and return the Palette synchronously.

AsyncTask<Bitmap!, Void!, Palette!>

Generate the Palette asynchronously.

Palette.Builder

Set the maximum number of colors to use in the quantization step when using a android.graphics.Bitmap as the source.

Public constructors

<init>

Builder(bitmap: Bitmap)

Construct a new Builder using a source Bitmap

<init>

Builder(swatches: MutableList<Palette.Swatch!>)

Construct a new Builder using a list of Swatch instances. Typically only used for testing.

Public methods

addTarget

fun addTarget(target: Target): Palette.Builder

Add a target profile to be generated in the palette.

You can retrieve the result via Palette#getSwatchForTarget(Target).

addFilter

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 Palette.Filter!: filter to add.

resizeBitmapSize

fun resizeBitmapSize(maxDimension: Int): Palette.Builder

Set the resize value when using a android.graphics.Bitmap 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 Int: the number of pixels that the max dimension should be scaled down to, or any value <= 0 to disable resizing.

clearTargets

fun clearTargets(): Palette.Builder

Clear all added targets. This includes any default targets added automatically by Palette.

resizeBitmapArea

fun resizeBitmapArea(area: Int): Palette.Builder

Set the resize value when using a android.graphics.Bitmap 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 Int: the number of pixels that the intermediary scaled down Bitmap should cover, or any value <= 0 to disable resizing.

clearRegion

fun clearRegion(): Palette.Builder

Clear any previously region set via #setRegion(int, int, int, int).

clearFilters

fun clearFilters(): Palette.Builder

Clear all added filters. This includes any default filters added automatically by Palette.

setRegion

fun setRegion(left: Int, top: Int, right: Int, bottom: 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 Bitmap.

Parameters
left Int: The left side of the rectangle used for the region.
top Int: The top of the rectangle used for the region.
right Int: The right side of the rectangle used for the region.
bottom Int: The bottom of the rectangle used for the region.

generate

fun generate(): Palette

Generate and return the Palette synchronously.

generate

fun generate(listener: Palette.PaletteAsyncListener): AsyncTask<Bitmap!, Void!, Palette!>

Generate the Palette asynchronously. The provided listener's PaletteAsyncListener#onGenerated method will be called with the palette when generated.

maximumColorCount

fun maximumColorCount(colors: Int): Palette.Builder

Set the maximum number of colors to use in the quantization step when using a android.graphics.Bitmap 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.