Skip to content

Most visited

Recently visited

navigation

Palette.Builder

public static final class Palette.Builder
extends Object

java.lang.Object
   ↳ android.support.v7.graphics.Palette.Builder


Builder class for generating Palette instances.

Summary

Public constructors

Palette.Builder(Bitmap bitmap)

Construct a new Palette.Builder using a source Bitmap

Palette.Builder(List<Palette.Swatch> swatches)

Construct a new Palette.Builder using a list of Palette.Swatch instances.

Public methods

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.

Palette.Builder addTarget(Target target)

Add a target profile to be generated in the palette.

Palette.Builder clearFilters()

Clear all added filters.

Palette.Builder clearRegion()

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

Palette.Builder clearTargets()

Clear all added targets.

AsyncTask<BitmapVoidPalette> generate(Palette.PaletteAsyncListener listener)

Generate the Palette asynchronously.

Palette generate()

Generate and return the Palette synchronously.

Palette.Builder maximumColorCount(int colors)

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

Palette.Builder resizeBitmapArea(int area)

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

Palette.Builder resizeBitmapSize(int maxDimension)

This method was deprecated in API level 23.2.0. Using resizeBitmapArea(int) is preferred since it can handle abnormal aspect ratios more gracefully.

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.

Inherited methods

From class java.lang.Object

Public constructors

Palette.Builder

added in version 22.1.0
Palette.Builder (Bitmap bitmap)

Construct a new Palette.Builder using a source Bitmap

Parameters
bitmap Bitmap

Palette.Builder

added in version 22.1.0
Palette.Builder (List<Palette.Swatch> swatches)

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

Parameters
swatches List

Public methods

addFilter

added in version 23.0.0
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 Palette.Filter: filter to add.

Returns
Palette.Builder

addTarget

added in version 23.2.0
Palette.Builder addTarget (Target target)

Add a target profile to be generated in the palette.

You can retrieve the result via getSwatchForTarget(Target).

Parameters
target Target

Returns
Palette.Builder

clearFilters

added in version 23.0.0
Palette.Builder clearFilters ()

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

Returns
Palette.Builder

clearRegion

added in version 23.1.0
Palette.Builder clearRegion ()

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

Returns
Palette.Builder

clearTargets

added in version 23.2.0
Palette.Builder clearTargets ()

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

Returns
Palette.Builder

generate

added in version 22.1.0
AsyncTask<BitmapVoidPalette> generate (Palette.PaletteAsyncListener listener)

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

Parameters
listener Palette.PaletteAsyncListener

Returns
AsyncTask<BitmapVoidPalette>

generate

added in version 22.1.0
Palette generate ()

Generate and return the Palette synchronously.

Returns
Palette

maximumColorCount

added in version 22.1.0
Palette.Builder maximumColorCount (int colors)

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

Parameters
colors int

Returns
Palette.Builder

resizeBitmapArea

added in version 23.2.0
Palette.Builder resizeBitmapArea (int area)

Set the resize value when using a 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.

Returns
Palette.Builder

resizeBitmapSize

added in version 22.1.0
Palette.Builder resizeBitmapSize (int maxDimension)

This method was deprecated in API level 23.2.0.
Using resizeBitmapArea(int) is preferred since it can handle abnormal aspect ratios more gracefully.

Set the resize value when using a 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.

Returns
Palette.Builder

setRegion

added in version 23.1.0
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 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.

Returns
Palette.Builder

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)