public final class

Palette.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.palette.graphics.Palette.Builder

Overview

Builder class for generating Palette instances.

Summary

Constructors
publicBuilder(Bitmap bitmap)

Construct a new Palette.Builder using a source Bitmap

Methods
public Palette.BuilderaddFilter(Palette.Filter filter)

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

public Palette.BuilderaddTarget(Target target)

Add a target profile to be generated in the palette.

public Palette.BuilderclearFilters()

Clear all added filters.

public Palette.BuilderclearRegion()

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

public Palette.BuilderclearTargets()

Clear all added targets.

public Palettegenerate()

Generate and return the Palette synchronously.

public <any>generate(Palette.PaletteAsyncListener listener)

Generate the Palette asynchronously.

public Palette.BuildermaximumColorCount(int colors)

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

public Palette.BuilderresizeBitmapArea(int area)

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

public Palette.BuilderresizeBitmapSize(int maxDimension)

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

public Palette.BuildersetRegion(int left, int top, int right, int bottom)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Bitmap bitmap)

Construct a new Palette.Builder using a source Bitmap

Methods

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

public Palette.Builder resizeBitmapSize(int maxDimension)

Deprecated: Using Palette.Builder.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: the number of pixels that the max dimension should be scaled down to, or any value <= 0 to disable resizing.

public 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:

area: the number of pixels that the intermediary scaled down Bitmap should cover, or any value <= 0 to disable resizing.

public Palette.Builder clearFilters()

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

public 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:

filter: filter to add.

public Palette.Builder setRegion(int left, int top, int right, 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:

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

public Palette.Builder clearRegion()

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

public Palette.Builder addTarget(Target target)

Add a target profile to be generated in the palette.

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

public Palette.Builder clearTargets()

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

public Palette generate()

Generate and return the Palette synchronously.

public <any> generate(Palette.PaletteAsyncListener listener)

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