public final class Palette extends Object
A number of colors with different profiles are extracted from the image:
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 } });
Modifier and Type | Class and Description |
---|---|
static class |
Palette.Builder
Builder class for generating
Palette instances. |
static interface |
Palette.Filter
A Filter provides a mechanism for exercising fine-grained control over which colors
are valid within a resulting
Palette . |
static interface |
Palette.PaletteAsyncListener
Listener to be used with
generateAsync(Bitmap, PaletteAsyncListener) or
generateAsync(Bitmap, int, PaletteAsyncListener) |
static class |
Palette.Swatch
Represents a color swatch generated from an image's palette.
|
Modifier and Type | Method and Description |
---|---|
static Palette.Builder |
from(Bitmap bitmap)
Start generating a
Palette with the returned Palette.Builder instance. |
static Palette |
from(List<Palette.Swatch> swatches)
Generate a
Palette from the pre-generated list of Palette.Swatch swatches. |
static Palette |
generate(Bitmap bitmap)
Deprecated.
Use
Palette.Builder to generate the Palette. |
static Palette |
generate(Bitmap bitmap,
int numColors)
Deprecated.
Use
Palette.Builder to generate the Palette. |
static AsyncTask<Bitmap,Void,Palette> |
generateAsync(Bitmap bitmap,
int numColors,
Palette.PaletteAsyncListener listener)
Deprecated.
Use
Palette.Builder to generate the Palette. |
static AsyncTask<Bitmap,Void,Palette> |
generateAsync(Bitmap bitmap,
Palette.PaletteAsyncListener listener)
Deprecated.
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.
|
List<Palette.Swatch> |
getSwatches()
Returns all of the swatches which make up 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<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.
|
public static Palette.Builder from(Bitmap bitmap)
Palette
with the returned Palette.Builder
instance.public static Palette from(List<Palette.Swatch> swatches)
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.@Deprecated public static Palette generate(Bitmap bitmap)
Palette.Builder
to generate the Palette.@Deprecated public static Palette generate(Bitmap bitmap, int numColors)
Palette.Builder
to generate the Palette.@Deprecated public static AsyncTask<Bitmap,Void,Palette> generateAsync(Bitmap bitmap, Palette.PaletteAsyncListener listener)
Palette.Builder
to generate the Palette.@Deprecated public static AsyncTask<Bitmap,Void,Palette> generateAsync(Bitmap bitmap, int numColors, Palette.PaletteAsyncListener listener)
Palette.Builder
to generate the Palette.@NonNull public List<Palette.Swatch> getSwatches()
@NonNull public List<Target> getTargets()
@Nullable public Palette.Swatch getVibrantSwatch()
Target.VIBRANT
@Nullable public Palette.Swatch getLightVibrantSwatch()
Target.LIGHT_VIBRANT
@Nullable public Palette.Swatch getDarkVibrantSwatch()
Target.DARK_VIBRANT
@Nullable public Palette.Swatch getMutedSwatch()
Target.MUTED
@Nullable public Palette.Swatch getLightMutedSwatch()
Target.LIGHT_MUTED
@Nullable public Palette.Swatch getDarkMutedSwatch()
Target.DARK_MUTED
public int getVibrantColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetVibrantSwatch()
public int getLightVibrantColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetLightVibrantSwatch()
public int getDarkVibrantColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetDarkVibrantSwatch()
public int getMutedColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetMutedSwatch()
public int getLightMutedColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetLightMutedSwatch()
public int getDarkMutedColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetDarkMutedSwatch()
@Nullable public Palette.Swatch getSwatchForTarget(@NonNull Target target)
null
if one
could not be found.public int getColorForTarget(@NonNull Target target, int defaultColor)
defaultColor
- value to return if the swatch isn't available@Nullable public Palette.Swatch getDominantSwatch()
The dominant swatch is defined as the swatch with the greatest population (frequency) within the palette.
public int getDominantColor(int defaultColor)
defaultColor
- value to return if the swatch isn't availablegetDominantSwatch()