The Android Developer Challenge is back! Submit your idea before December 2.

Builder

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

Builder class for generating Palette instances.

Summary

Public constructors

<init>(@NonNull bitmap: Bitmap)

Construct a new Builder using a source Bitmap

<init>(@NonNull swatches: MutableList<Palette.Swatch!>)

Construct a new Builder using a list of Swatch instances.

Public methods

Palette.Builder

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

Palette.Builder
addTarget(@NonNull target: Target)

Add a target profile to be generated in the palette.

Palette.Builder

Clear all added filters.

Palette.Builder

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

Palette.Builder

Clear all added targets.

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.

Palette.Builder

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

Palette.Builder
resizeBitmapSize(maxDimension: Int)

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

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

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

Public constructors

<init>

Builder(@NonNull bitmap: Bitmap)

Construct a new Builder using a source Bitmap

<init>

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

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

Public methods

addFilter

@NonNull 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.

addTarget

@NonNull fun addTarget(@NonNull target: Target): Palette.Builder

Add a target profile to be generated in the palette.

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

clearFilters

@NonNull fun clearFilters(): Palette.Builder

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

clearRegion

@NonNull fun clearRegion(): Palette.Builder

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

clearTargets

@NonNull fun clearTargets(): Palette.Builder

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

generate

@NonNull fun generate(): Palette

Generate and return the Palette synchronously.

generate

@NonNull fun generate(@NonNull 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

@NonNull 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.

resizeBitmapArea

@NonNull 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.

resizeBitmapSize

@NonNull fun resizeBitmapSize(maxDimension: Int): Palette.Builder

Deprecated: Using resizeBitmapArea(int) is preferred since it can handle abnormal aspect ratios more gracefully.

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.

setRegion

@NonNull fun setRegion(@Px left: Int, @Px top: Int, @Px right: Int, @Px 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.