java.lang.Object | |
↳ | net.pierrox.lightning_launcher.script.api.palette.Palette |
A helper class to extract prominent colors from an image. This is extracted from https://android.googlesource.com/platform/frameworks/support/+/master/v7/palette/src/android/support/v7/graphics. For an example on how to use this class in Lightning Launcher, please have a look at http://www.pierrox.net/android/applications/lightning_launcher/wiki/doku.php?id=script_palette
A number of colors with different profiles are extracted from the image:
Instances can be created with the synchronous factory methods generate(android.graphics.Bitmap)
and
generate(android.graphics.Bitmap, int)
.
These should be called on a background thread, ideally the one in
which you load your images on. Sometimes that is not possible, so asynchronous factory methods
have also been provided: generateAsync(android.graphics.Bitmap, net.pierrox.lightning_launcher.script.api.palette.Palette.PaletteAsyncListener)
and
generateAsync(android.graphics.Bitmap, int, net.pierrox.lightning_launcher.script.api.palette.Palette.PaletteAsyncListener)
. These can be used as so:
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { // Do something with colors... } });
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
interface | Palette.PaletteAsyncListener | Listener to be used with generateAsync(android.graphics.Bitmap, net.pierrox.lightning_launcher.script.api.palette.Palette.PaletteAsyncListener) or
generateAsync(android.graphics.Bitmap, int, net.pierrox.lightning_launcher.script.api.palette.Palette.PaletteAsyncListener)
|
|||||||||
class | Palette.Swatch | Represents a color swatch generated from an image's palette. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static Palette |
generate(Bitmap bitmap, int numColors)
Generate a
Palette from a android.graphics.Bitmap using the specified numColors . | ||||||||||
static Palette |
generate(Bitmap bitmap)
Generate a
Palette from a android.graphics.Bitmap using the default number of colors. | ||||||||||
static AsyncTask<Bitmap, Void, Palette> |
generateAsync(Bitmap bitmap, int numColors, Palette.PaletteAsyncListener listener)
Generate a
Palette asynchronously. | ||||||||||
static AsyncTask<Bitmap, Void, Palette> |
generateAsync(Bitmap bitmap, Palette.PaletteAsyncListener listener)
Generate a
Palette asynchronously. | ||||||||||
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 |
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.
| ||||||||||
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.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Generate a Palette
from a android.graphics.Bitmap using the specified numColors
.
Good values for numColors
depend on the source image type.
For landscapes, a good values are in the range 12-16. For images which are largely made up
of people's faces then this value should be increased to 24-32.
numColors | The maximum number of colors in the generated palette. Increasing this number will increase the time needed to compute the values. |
---|
Generate a Palette
from a android.graphics.Bitmap using the default number of colors.
Generate a Palette
asynchronously. onGenerated(net.pierrox.lightning_launcher.script.api.palette.Palette)
will be called with the created instance. The resulting Palette
is the same as what
would be created by calling generate(android.graphics.Bitmap, int)
.
listener | Listener to be invoked when the Palette has been generated. |
---|
Generate a Palette
asynchronously. onGenerated(net.pierrox.lightning_launcher.script.api.palette.Palette)
will be called with the created instance. The resulting Palette
is the same as
what would be created by calling generate(android.graphics.Bitmap)
.
listener | Listener to be invoked when the Palette has been generated. |
---|
Returns a muted and dark color from the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns a muted and dark swatch from the palette. Might be null.
Returns a dark and vibrant color from the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns a dark and vibrant swatch from the palette. Might be null.
Returns a muted and light color from the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns a muted and light swatch from the palette. Might be null.
Returns a light and vibrant color from the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns a light and vibrant swatch from the palette. Might be null.
Returns a muted color from the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns the most vibrant color in the palette as an RGB packed int.
defaultColor | value to return if the swatch isn't available |
---|
Returns the most vibrant swatch in the palette. Might be null.