Skip to content

Most visited

Recently visited

navigation

Palette

public final class Palette
extends Object

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


A helper class to extract prominent colors from an image.

A number of colors with different profiles are extracted from the image:

  • Vibrant
  • Vibrant Dark
  • Vibrant Light
  • Muted
  • Muted Dark
  • Muted Light
These can be retrieved from the appropriate getter method.

Instances are created with a Palette.Builder which supports several options to tweak the generated Palette. See that class' documentation for more information.

Generation should always be completed on a background thread, ideally the one in which you load your image on. Palette.Builder supports both synchronous and asynchronous generation:

 // Synchronous
 Palette p = Palette.from(bitmap).generate();

 // Asynchronous
 Palette.from(bitmap).generate(new PaletteAsyncListener() {
     public void onGenerated(Palette p) {
         // Use generated instance
     }
 });
 

Summary

Nested classes

class Palette.Builder

Builder class for generating Palette instances. 

interface Palette.Filter

A Filter provides a mechanism for exercising fine-grained control over which colors are valid within a resulting Palette

interface Palette.PaletteAsyncListener

Listener to be used with generateAsync(Bitmap, PaletteAsyncListener) or generateAsync(Bitmap, int, PaletteAsyncListener)  

class Palette.Swatch

Represents a color swatch generated from an image's palette. 

Public methods

static Palette from(List<Palette.Swatch> swatches)

Generate a Palette from the pre-generated list of Palette.Swatch swatches.

static Palette.Builder from(Bitmap bitmap)

Start generating a Palette with the returned Palette.Builder instance.

static Palette generate(Bitmap bitmap, int numColors)

This method was deprecated in API level 22.1.0. Use Palette.Builder to generate the Palette.

static Palette generate(Bitmap bitmap)

This method was deprecated in API level 22.1.0. Use Palette.Builder to generate the Palette.

static AsyncTask<BitmapVoidPalette> generateAsync(Bitmap bitmap, int numColors, Palette.PaletteAsyncListener listener)

This method was deprecated in API level 22.1.0. Use Palette.Builder to generate the Palette.

static AsyncTask<BitmapVoidPalette> generateAsync(Bitmap bitmap, Palette.PaletteAsyncListener listener)

This method was deprecated in API level 22.1.0. Use Palette.Builder to generate the Palette.

int getColorForTarget(Target target, int defaultColor)

Returns the selected color for the given target from the palette as an RGB packed int.

int getDarkMutedColor(int defaultColor)

Returns a muted and dark color from the palette as an RGB packed int.

Palette.Swatch getDarkMutedSwatch()

Returns a muted and dark swatch from the palette.

int getDarkVibrantColor(int defaultColor)

Returns a dark and vibrant color from the palette as an RGB packed int.

Palette.Swatch getDarkVibrantSwatch()

Returns a dark and vibrant swatch from the palette.

int getDominantColor(int defaultColor)

Returns the color of the dominant swatch from the palette, as an RGB packed int.

Palette.Swatch getDominantSwatch()

Returns the dominant swatch from the palette.

int getLightMutedColor(int defaultColor)

Returns a muted and light color from the palette as an RGB packed int.

Palette.Swatch getLightMutedSwatch()

Returns a muted and light swatch from the palette.

int getLightVibrantColor(int defaultColor)

Returns a light and vibrant color from the palette as an RGB packed int.

Palette.Swatch getLightVibrantSwatch()

Returns a light and vibrant swatch from the palette.

int getMutedColor(int defaultColor)

Returns a muted color from the palette as an RGB packed int.

Palette.Swatch getMutedSwatch()

Returns a muted swatch from the palette.

Palette.Swatch getSwatchForTarget(Target target)

Returns the selected swatch for the given target from the palette, or null if one could not be found.

List<Palette.Swatch> getSwatches()

Returns all of the swatches which make up the palette.

List<Target> getTargets()

Returns the targets used to generate this palette.

int getVibrantColor(int defaultColor)

Returns the most vibrant color in the palette as an RGB packed int.

Palette.Swatch getVibrantSwatch()

Returns the most vibrant swatch in the palette.

Inherited methods

From class java.lang.Object

Public methods

from

added in version 22.0.0
Palette from (List<Palette.Swatch> swatches)

Generate a Palette from the pre-generated list of Palette.Swatch swatches. This is useful for testing, or if you want to resurrect a Palette instance from a list of swatches. Will return null if the swatches is null.

Parameters
swatches List

Returns
Palette

from

added in version 22.1.0
Palette.Builder from (Bitmap bitmap)

Start generating a Palette with the returned Palette.Builder instance.

Parameters
bitmap Bitmap

Returns
Palette.Builder

generate

added in version 22.0.0
Palette generate (Bitmap bitmap, 
                int numColors)

This method was deprecated in API level 22.1.0.
Use Palette.Builder to generate the Palette.

Parameters
bitmap Bitmap

numColors int

Returns
Palette

generate

added in version 22.0.0
Palette generate (Bitmap bitmap)

This method was deprecated in API level 22.1.0.
Use Palette.Builder to generate the Palette.

Parameters
bitmap Bitmap

Returns
Palette

generateAsync

added in version 22.0.0
AsyncTask<BitmapVoidPalette> generateAsync (Bitmap bitmap, 
                int numColors, 
                Palette.PaletteAsyncListener listener)

This method was deprecated in API level 22.1.0.
Use Palette.Builder to generate the Palette.

Parameters
bitmap Bitmap

numColors int

listener Palette.PaletteAsyncListener

Returns
AsyncTask<BitmapVoidPalette>

generateAsync

added in version 22.0.0
AsyncTask<BitmapVoidPalette> generateAsync (Bitmap bitmap, 
                Palette.PaletteAsyncListener listener)

This method was deprecated in API level 22.1.0.
Use Palette.Builder to generate the Palette.

Parameters
bitmap Bitmap

listener Palette.PaletteAsyncListener

Returns
AsyncTask<BitmapVoidPalette>

getColorForTarget

added in version 23.2.0
int getColorForTarget (Target target, 
                int defaultColor)

Returns the selected color for the given target from the palette as an RGB packed int.

Parameters
target Target

defaultColor int: value to return if the swatch isn't available

Returns
int

getDarkMutedColor

added in version 22.0.0
int getDarkMutedColor (int defaultColor)

Returns a muted and dark color from the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getDarkMutedSwatch

added in version 22.0.0
Palette.Swatch getDarkMutedSwatch ()

Returns a muted and dark swatch from the palette. Might be null.

Returns
Palette.Swatch

See also:

getDarkVibrantColor

added in version 22.0.0
int getDarkVibrantColor (int defaultColor)

Returns a dark and vibrant color from the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getDarkVibrantSwatch

added in version 22.0.0
Palette.Swatch getDarkVibrantSwatch ()

Returns a dark and vibrant swatch from the palette. Might be null.

Returns
Palette.Swatch

See also:

getDominantColor

added in version 24.2.0
int getDominantColor (int defaultColor)

Returns the color of the dominant swatch from the palette, as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getDominantSwatch

added in version 24.2.0
Palette.Swatch getDominantSwatch ()

Returns the dominant swatch from the palette.

The dominant swatch is defined as the swatch with the greatest population (frequency) within the palette.

Returns
Palette.Swatch

getLightMutedColor

added in version 22.0.0
int getLightMutedColor (int defaultColor)

Returns a muted and light color from the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getLightMutedSwatch

added in version 22.0.0
Palette.Swatch getLightMutedSwatch ()

Returns a muted and light swatch from the palette. Might be null.

Returns
Palette.Swatch

See also:

getLightVibrantColor

added in version 22.0.0
int getLightVibrantColor (int defaultColor)

Returns a light and vibrant color from the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getLightVibrantSwatch

added in version 22.0.0
Palette.Swatch getLightVibrantSwatch ()

Returns a light and vibrant swatch from the palette. Might be null.

Returns
Palette.Swatch

See also:

getMutedColor

added in version 22.0.0
int getMutedColor (int defaultColor)

Returns a muted color from the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getMutedSwatch

added in version 22.0.0
Palette.Swatch getMutedSwatch ()

Returns a muted swatch from the palette. Might be null.

Returns
Palette.Swatch

See also:

getSwatchForTarget

added in version 23.2.0
Palette.Swatch getSwatchForTarget (Target target)

Returns the selected swatch for the given target from the palette, or null if one could not be found.

Parameters
target Target

Returns
Palette.Swatch

getSwatches

added in version 22.0.0
List<Palette.Swatch> getSwatches ()

Returns all of the swatches which make up the palette.

Returns
List<Palette.Swatch>

getTargets

added in version 23.2.0
List<Target> getTargets ()

Returns the targets used to generate this palette.

Returns
List<Target>

getVibrantColor

added in version 22.0.0
int getVibrantColor (int defaultColor)

Returns the most vibrant color in the palette as an RGB packed int.

Parameters
defaultColor int: value to return if the swatch isn't available

Returns
int

See also:

getVibrantSwatch

added in version 22.0.0
Palette.Swatch getVibrantSwatch ()

Returns the most vibrant swatch in the palette. Might be null.

Returns
Palette.Swatch

See also:

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 one-minute survey?
Help us improve Android tools and documentation.