Palette
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 |
|---|
class Palette.BuilderBuilder class for generating |
interface Palette.FilterA Filter provides a mechanism for exercising fine-grained control over which colors are valid within a resulting |
interface Palette.PaletteAsyncListenerListener to be used with |
class Palette.SwatchRepresents a color swatch generated from an image's palette. |
Public functions |
|
|---|---|
java-static Palette.Builder |
Start generating a |
java-static Palette |
from(swatches: (Mutable)List<Palette.Swatch!>)Generate a |
java-static Palette |
This function is deprecated. Use |
java-static Palette |
This function is deprecated. Use |
java-static AsyncTask<Bitmap!, Void!, Palette!> |
This function is deprecated. Use |
java-static AsyncTask<Bitmap!, Void!, Palette!> |
This function is deprecated. Use |
@ColorInt Int |
getColorForTarget(target: Target, defaultColor: @ColorInt Int)Returns the selected color for the given target from the palette as an RGB packed int. |
@ColorInt Int |
getDarkMutedColor(defaultColor: @ColorInt Int)Returns a muted and dark color from the palette as an RGB packed int. |
Palette.Swatch? |
Returns a muted and dark swatch from the palette. |
@ColorInt Int |
getDarkVibrantColor(defaultColor: @ColorInt Int)Returns a dark and vibrant color from the palette as an RGB packed int. |
Palette.Swatch? |
Returns a dark and vibrant swatch from the palette. |
@ColorInt Int |
getDominantColor(defaultColor: @ColorInt Int)Returns the color of the dominant swatch from the palette, as an RGB packed int. |
Palette.Swatch? |
Returns the dominant swatch from the palette. |
@ColorInt Int |
getLightMutedColor(defaultColor: @ColorInt Int)Returns a muted and light color from the palette as an RGB packed int. |
Palette.Swatch? |
Returns a muted and light swatch from the palette. |
@ColorInt Int |
getLightVibrantColor(defaultColor: @ColorInt Int)Returns a light and vibrant color from the palette as an RGB packed int. |
Palette.Swatch? |
Returns a light and vibrant swatch from the palette. |
@ColorInt Int |
getMutedColor(defaultColor: @ColorInt Int)Returns a muted color from the palette as an RGB packed int. |
Palette.Swatch? |
Returns a muted swatch from the palette. |
Palette.Swatch? |
getSwatchForTarget(target: Target)Returns the selected swatch for the given target from the palette, or |
(Mutable)List<Palette.Swatch!> |
Returns all of the swatches which make up the palette. |
(Mutable)List<Target!> |
Returns the targets used to generate this palette. |
@ColorInt Int |
getVibrantColor(defaultColor: @ColorInt Int)Returns the most vibrant color in the palette as an RGB packed int. |
Palette.Swatch? |
Returns the most vibrant swatch in the palette. |
Extension functions |
|
|---|---|
inline operator Palette.Swatch? |
Returns the selected swatch for the given target from the palette, or |
Public functions
from
java-static fun from(bitmap: Bitmap): Palette.Builder
Start generating a Palette with the returned Builder instance.
from
java-static fun from(swatches: (Mutable)List<Palette.Swatch!>): Palette
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.
java-static fungenerateAsync(bitmap: Bitmap, listener: Palette.PaletteAsyncListener): AsyncTask<Bitmap!, Void!, Palette!>
java-static fungenerateAsync(
bitmap: Bitmap,
numColors: Int,
listener: Palette.PaletteAsyncListener
): AsyncTask<Bitmap!, Void!, Palette!>
getColorForTarget
fun getColorForTarget(target: Target, defaultColor: @ColorInt Int): @ColorInt Int
Returns the selected color for the given target from the palette as an RGB packed int.
getDarkMutedColor
fun getDarkMutedColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns a muted and dark color from the palette as an RGB packed int.
| See also | |
|---|---|
getDarkMutedSwatch |
getDarkMutedSwatch
fun getDarkMutedSwatch(): Palette.Swatch?
Returns a muted and dark swatch from the palette. Might be null.
| See also | |
|---|---|
DARK_MUTED |
getDarkVibrantColor
fun getDarkVibrantColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns a dark and vibrant color from the palette as an RGB packed int.
| See also | |
|---|---|
getDarkVibrantSwatch |
getDarkVibrantSwatch
fun getDarkVibrantSwatch(): Palette.Swatch?
Returns a dark and vibrant swatch from the palette. Might be null.
| See also | |
|---|---|
DARK_VIBRANT |
getDominantColor
fun getDominantColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns the color of the dominant swatch from the palette, as an RGB packed int.
| See also | |
|---|---|
getDominantSwatch |
getDominantSwatch
fun getDominantSwatch(): Palette.Swatch?
Returns the dominant swatch from the palette.
The dominant swatch is defined as the swatch with the greatest population (frequency) within the palette.
getLightMutedColor
fun getLightMutedColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns a muted and light color from the palette as an RGB packed int.
| See also | |
|---|---|
getLightMutedSwatch |
getLightMutedSwatch
fun getLightMutedSwatch(): Palette.Swatch?
Returns a muted and light swatch from the palette. Might be null.
| See also | |
|---|---|
LIGHT_MUTED |
getLightVibrantColor
fun getLightVibrantColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns a light and vibrant color from the palette as an RGB packed int.
| See also | |
|---|---|
getLightVibrantSwatch |
getLightVibrantSwatch
fun getLightVibrantSwatch(): Palette.Swatch?
Returns a light and vibrant swatch from the palette. Might be null.
| See also | |
|---|---|
LIGHT_VIBRANT |
getMutedColor
fun getMutedColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns a muted color from the palette as an RGB packed int.
| See also | |
|---|---|
getMutedSwatch |
getMutedSwatch
fun getMutedSwatch(): Palette.Swatch?
Returns a muted swatch from the palette. Might be null.
| See also | |
|---|---|
MUTED |
getSwatchForTarget
fun getSwatchForTarget(target: Target): Palette.Swatch?
Returns the selected swatch for the given target from the palette, or null if one could not be found.
getSwatches
fun getSwatches(): (Mutable)List<Palette.Swatch!>
Returns all of the swatches which make up the palette.
getTargets
fun getTargets(): (Mutable)List<Target!>
Returns the targets used to generate this palette.
getVibrantColor
fun getVibrantColor(defaultColor: @ColorInt Int): @ColorInt Int
Returns the most vibrant color in the palette as an RGB packed int.
| See also | |
|---|---|
getVibrantSwatch |
getVibrantSwatch
fun getVibrantSwatch(): Palette.Swatch?
Returns the most vibrant swatch in the palette. Might be null.
| See also | |
|---|---|
VIBRANT |
Extension functions
Palette.get
inline operator fun Palette.get(target: Target): Palette.Swatch?
Returns the selected swatch for the given target from the palette, or null if one could not be found.
| See also | |
|---|---|
getSwatchForTarget |