We can extract the colors from the bitmap.
Add the library in your app gradle.
compile 'com.android.support:palette-v7:25.1.0'
We have four ways to create the palette.
// Now Palette.from(bitmap) is the same as Palette.Builder(bitmap).
// Synchronous methods.
// --------------------------------
// These should be used when you have access to the underlying image loading thread.
// Picasso allows this through a Transformation. For other libraries, YMMV.
// Uses the default palette size (16).
Palette p = Palette.from(bitmap).generate();
// Allows you to specify the maximum palette size, in this case 24.
Palette p = Palette.from(bitmap).maximumColorCount(24).generate();
// Asynchronous methods
// --------------------------------
// This is the quick and easy integration path. Internally uses an AsyncTask so
// this may not be optimal (since you're dipping in and out of threads)
// Uses the default palette size (16).
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// Here's your generated palette
}
});
// Allows you to specify the maximum palette size, in this case 24.
Palette.from(bitmap).maximumColorCount(24).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// Here's your generated palette
}
});
We often use Vibrant and Dark Vibrant.
// Vibrant.
Palette.getVibrantSwatch()
// Vibrant dark.
Palette.getDarkVibrantSwatch()
// Vibrant light.
Palette.getLightVibrantSwatch()
// Muted.
Palette.getMutedSwatch()
// Muted dark.
Palette.getDarkMutedSwatch()
// Muted light.
Palette.getLightMutedSwatch()