Palette
public final class 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
Instances are created with a 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. 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 types |
|---|
public final class Palette.BuilderBuilder class for generating |
public interface Palette.FilterA Filter provides a mechanism for exercising fine-grained control over which colors are valid within a resulting |
public interface Palette.PaletteAsyncListenerListener to be used with |
public final class Palette.SwatchRepresents a color swatch generated from an image's palette. |
Public methods |
|
|---|---|
static @NonNull Palette.Builder |
Start generating a |
static @NonNull Palette |
from(@NonNull List<Palette.Swatch> swatches)Generate a |
static @NonNull Palette |
This method is deprecated. Use |
static @NonNull Palette |
This method is deprecated. Use |
static @NonNull AsyncTask<Bitmap, Void, Palette> |
This method is deprecated. Use |
static @NonNull AsyncTask<Bitmap, Void, Palette> |
This method is deprecated. Use |
@ColorInt int |
getColorForTarget(@NonNull Target target, @ColorInt int defaultColor)Returns the selected color for the given target from the palette as an RGB packed int. |
@ColorInt int |
getDarkMutedColor(@ColorInt int defaultColor)Returns a muted and dark color from the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns a muted and dark swatch from the palette. |
@ColorInt int |
getDarkVibrantColor(@ColorInt int defaultColor)Returns a dark and vibrant color from the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns a dark and vibrant swatch from the palette. |
@ColorInt int |
getDominantColor(@ColorInt int defaultColor)Returns the color of the dominant swatch from the palette, as an RGB packed int. |
@Nullable Palette.Swatch |
Returns the dominant swatch from the palette. |
@ColorInt int |
getLightMutedColor(@ColorInt int defaultColor)Returns a muted and light color from the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns a muted and light swatch from the palette. |
@ColorInt int |
getLightVibrantColor(@ColorInt int defaultColor)Returns a light and vibrant color from the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns a light and vibrant swatch from the palette. |
@ColorInt int |
getMutedColor(@ColorInt int defaultColor)Returns a muted color from the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns a muted swatch from the palette. |
@Nullable Palette.Swatch |
getSwatchForTarget(@NonNull Target target)Returns the selected swatch for the given target from the palette, or |
@NonNull List<Palette.Swatch> |
Returns all of the swatches which make up the palette. |
@NonNull List<Target> |
Returns the targets used to generate this palette. |
@ColorInt int |
getVibrantColor(@ColorInt int defaultColor)Returns the most vibrant color in the palette as an RGB packed int. |
@Nullable Palette.Swatch |
Returns the most vibrant swatch in the palette. |
Extension functions |
|
|---|---|
final Palette.Swatch |
Returns the selected swatch for the given target from the palette, or |
Public methods
from
public static @NonNull Palette.Builder from(@NonNull Bitmap bitmap)
Start generating a Palette with the returned Builder instance.
from
public static @NonNull Palette from(@NonNull 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.
public static @NonNull AsyncTask<Bitmap, Void, Palette>generateAsync(
@NonNull Bitmap bitmap,
@NonNull Palette.PaletteAsyncListener listener
)
public static @NonNull AsyncTask<Bitmap, Void, Palette>generateAsync(
@NonNull Bitmap bitmap,
int numColors,
@NonNull Palette.PaletteAsyncListener listener
)
getColorForTarget
public @ColorInt int getColorForTarget(@NonNull Target target, @ColorInt int defaultColor)
Returns the selected color for the given target from the palette as an RGB packed int.
getDarkMutedColor
public @ColorInt int getDarkMutedColor(@ColorInt int defaultColor)
Returns a muted and dark color from the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getDarkMutedSwatch |
getDarkMutedSwatch
public @Nullable Palette.Swatch getDarkMutedSwatch()
Returns a muted and dark swatch from the palette. Might be null.
| See also | |
|---|---|
DARK_MUTED |
getDarkVibrantColor
public @ColorInt int getDarkVibrantColor(@ColorInt int defaultColor)
Returns a dark and vibrant color from the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getDarkVibrantSwatch |
getDarkVibrantSwatch
public @Nullable Palette.Swatch getDarkVibrantSwatch()
Returns a dark and vibrant swatch from the palette. Might be null.
| See also | |
|---|---|
DARK_VIBRANT |
getDominantColor
public @ColorInt int getDominantColor(@ColorInt int defaultColor)
Returns the color of the dominant swatch from the palette, as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getDominantSwatch |
getDominantSwatch
public @Nullable 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.
getLightMutedColor
public @ColorInt int getLightMutedColor(@ColorInt int defaultColor)
Returns a muted and light color from the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getLightMutedSwatch |
getLightMutedSwatch
public @Nullable Palette.Swatch getLightMutedSwatch()
Returns a muted and light swatch from the palette. Might be null.
| See also | |
|---|---|
LIGHT_MUTED |
getLightVibrantColor
public @ColorInt int getLightVibrantColor(@ColorInt int defaultColor)
Returns a light and vibrant color from the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getLightVibrantSwatch |
getLightVibrantSwatch
public @Nullable Palette.Swatch getLightVibrantSwatch()
Returns a light and vibrant swatch from the palette. Might be null.
| See also | |
|---|---|
LIGHT_VIBRANT |
getMutedColor
public @ColorInt int getMutedColor(@ColorInt int defaultColor)
Returns a muted color from the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getMutedSwatch |
getMutedSwatch
public @Nullable Palette.Swatch getMutedSwatch()
Returns a muted swatch from the palette. Might be null.
| See also | |
|---|---|
MUTED |
getSwatchForTarget
public @Nullable Palette.Swatch getSwatchForTarget(@NonNull Target target)
Returns the selected swatch for the given target from the palette, or null if one could not be found.
getSwatches
public @NonNull List<Palette.Swatch> getSwatches()
Returns all of the swatches which make up the palette.
getTargets
public @NonNull List<Target> getTargets()
Returns the targets used to generate this palette.
getVibrantColor
public @ColorInt int getVibrantColor(@ColorInt int defaultColor)
Returns the most vibrant color in the palette as an RGB packed int.
| Parameters | |
|---|---|
@ColorInt int defaultColor |
value to return if the swatch isn't available |
| See also | |
|---|---|
getVibrantSwatch |
getVibrantSwatch
public @Nullable Palette.Swatch getVibrantSwatch()
Returns the most vibrant swatch in the palette. Might be null.
| See also | |
|---|---|
VIBRANT |
Extension functions
PaletteKt.get
public final Palette.Swatch PaletteKt.get(@NonNull Palette receiver, @NonNull Target target)
Returns the selected swatch for the given target from the palette, or null if one could not be found.
| See also | |
|---|---|
getSwatchForTarget |