Palette.Builder


class Palette.Builder


Builder class for generating Palette instances.

Summary

Public constructors

Builder(bitmap: Bitmap)

Construct a new Builder using a source Bitmap

Construct a new Builder using a list of Swatch instances.

Public functions

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(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.

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)

This function is deprecated.

Using resizeBitmapArea is preferred since it can handle abnormal aspect ratios more gracefully.

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

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

Public constructors

Builder

Added in 1.0.0
Builder(bitmap: Bitmap)

Construct a new Builder using a source Bitmap

Builder

Added in 1.0.0
Builder(swatches: (Mutable)List<Palette.Swatch!>)

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

Public functions

addFilter

Added in 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: Palette.Filter!

filter to add.

addTarget

Added in 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 getSwatchForTarget.

clearFilters

Added in 1.0.0
fun clearFilters(): Palette.Builder

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

clearRegion

Added in 1.0.0
fun clearRegion(): Palette.Builder

Clear any previously region set via setRegion.

clearTargets

Added in 1.0.0
fun clearTargets(): Palette.Builder

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

generate

Added in 1.0.0
fun generate(): Palette

Generate and return the Palette synchronously.

generate

Added in 1.0.0
Deprecated in 1.1.0-alpha01
fun generate(listener: Palette.PaletteAsyncListener): AsyncTask<Bitmap!, Void!, Palette!>

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

maximumColorCount

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
Deprecated in 1.0.0
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.

setRegion

Added in 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 Bitmap.

Parameters
left: @Px Int

The left side of the rectangle used for the region.

top: @Px Int

The top of the rectangle used for the region.

right: @Px Int

The right side of the rectangle used for the region.

bottom: @Px Int

The bottom of the rectangle used for the region.