Palette.Builder


public final class Palette.Builder


Builder class for generating Palette instances.

Summary

Public constructors

Construct a new Builder using a source Bitmap

Construct a new Builder using a list of Swatch instances.

Public methods

@NonNull Palette.Builder

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

@NonNull Palette.Builder

Add a target profile to be generated in the palette.

@NonNull Palette.Builder

Clear all added filters.

@NonNull Palette.Builder

Clear any previously region set via setRegion.

@NonNull Palette.Builder

Clear all added targets.

@NonNull Palette

Generate and return the Palette synchronously.

@NonNull AsyncTask<BitmapVoidPalette>

Generate the Palette asynchronously.

@NonNull Palette.Builder
maximumColorCount(int colors)

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

@NonNull Palette.Builder
resizeBitmapArea(int area)

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

@NonNull Palette.Builder
resizeBitmapSize(int maxDimension)

This method is deprecated.

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

@NonNull Palette.Builder
setRegion(@Px int left, @Px int top, @Px int right, @Px int bottom)

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

Public constructors

Builder

Added in 1.0.0
public Builder(@NonNull Bitmap bitmap)

Construct a new Builder using a source Bitmap

Builder

Added in 1.0.0
public Builder(@NonNull List<Palette.Swatch> swatches)

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

Public methods

addFilter

Added in 1.0.0
public @NonNull Palette.Builder addFilter(Palette.Filter filter)

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

Parameters
Palette.Filter filter

filter to add.

addTarget

Added in 1.0.0
public @NonNull Palette.Builder addTarget(@NonNull Target target)

Add a target profile to be generated in the palette.

You can retrieve the result via getSwatchForTarget.

clearFilters

Added in 1.0.0
public @NonNull Palette.Builder clearFilters()

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

clearRegion

Added in 1.0.0
public @NonNull Palette.Builder clearRegion()

Clear any previously region set via setRegion.

clearTargets

Added in 1.0.0
public @NonNull Palette.Builder clearTargets()

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

generate

Added in 1.0.0
public @NonNull Palette generate()

Generate and return the Palette synchronously.

generate

Added in 1.0.0
Deprecated in 1.1.0-alpha01
public @NonNull AsyncTask<BitmapVoidPalettegenerate(@NonNull Palette.PaletteAsyncListener listener)

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

maximumColorCount

Added in 1.0.0
public @NonNull Palette.Builder maximumColorCount(int colors)

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
public @NonNull Palette.Builder resizeBitmapArea(int area)

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
int area

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
public @NonNull Palette.Builder resizeBitmapSize(int maxDimension)

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
int maxDimension

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
public @NonNull Palette.Builder setRegion(@Px int left, @Px int top, @Px int right, @Px int bottom)

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
@Px int left

The left side of the rectangle used for the region.

@Px int top

The top of the rectangle used for the region.

@Px int right

The right side of the rectangle used for the region.

@Px int bottom

The bottom of the rectangle used for the region.