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

These can be retrieved from the appropriate getter method.

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:

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

Types

Link copied to clipboard
class Builder

Builder class for generating Palette instances.

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface Filter

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

Link copied to clipboard
class Swatch(val rgb: Int, val population: Int)

Represents a color swatch generated from an image's palette. The RGB color can be retrieved by calling rgb.

Properties

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

Returns the dominant swatch from the palette.

Link copied to clipboard

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

Functions

Link copied to clipboard
fun generate()
Link copied to clipboard
fun getColorForTarget(target: Target, defaultColor: Int): Int

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

Link copied to clipboard
fun getDarkMutedColor(defaultColor: Int): Int

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

Link copied to clipboard
fun getDarkVibrantColor(defaultColor: Int): Int

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

Link copied to clipboard
fun getDominantColor(defaultColor: Int): Int

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

Link copied to clipboard
fun getLightMutedColor(defaultColor: Int): Int

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

Link copied to clipboard
fun getLightVibrantColor(defaultColor: Int): Int

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

Link copied to clipboard
fun getMutedColor(defaultColor: Int): Int

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

Link copied to clipboard

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

Link copied to clipboard
fun getVibrantColor(defaultColor: Int): Int

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