added in version 22.1.0
belongs to Maven artifact com.android.support:palette-v7:28.0.0-alpha1

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<Bitmap, Void, Palette> 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<Bitmap, Void, Palette> 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.