Palette.Builder
public final class Palette.Builder
Builder class for generating Palette instances.
Summary
Public constructors |
|---|
Builder(@NonNull List<Palette.Swatch> swatches) |
Public methods |
|
|---|---|
@NonNull Palette.Builder |
addFilter(Palette.Filter filter)Add a filter to be able to have fine grained control over which colors are allowed in the resulting palette. |
@NonNull Palette.Builder |
Add a target profile to be generated in the palette. |
@NonNull Palette.Builder |
Clear all added filters. |
@NonNull Palette.Builder |
Clear any previously region set via |
@NonNull Palette.Builder |
Clear all added targets. |
@NonNull Palette |
generate()Generate and return the |
@NonNull AsyncTask<Bitmap, Void, Palette> |
generate(@NonNull Palette.PaletteAsyncListener listener)Generate the |
@NonNull Palette.Builder |
maximumColorCount(int colors)Set the maximum number of colors to use in the quantization step when using a |
@NonNull Palette.Builder |
resizeBitmapArea(int area)Set the resize value when using a |
@NonNull Palette.Builder |
This method is deprecated. Using |
@NonNull Palette.Builder |
Set a region of the bitmap to be used exclusively when calculating the palette. |
Public methods
addFilter
public @NonNull Palette.Builder addFilter(Palette.Filter filter)
Add a filter to be able to have fine grained control over which colors are allowed in the resulting palette.
| Parameters | |
|---|---|
Palette.Filter filter |
filter to add. |
addTarget
public @NonNull Palette.Builder addTarget(@NonNull Target target)
Add a target profile to be generated in the palette.
You can retrieve the result via getSwatchForTarget.
clearFilters
public @NonNull Palette.Builder clearFilters()
Clear all added filters. This includes any default filters added automatically by Palette.
clearRegion
public @NonNull Palette.Builder clearRegion()
Clear any previously region set via setRegion.
clearTargets
public @NonNull Palette.Builder clearTargets()
Clear all added targets. This includes any default targets added automatically by Palette.
generate
public @NonNull Palette generate()
Generate and return the Palette synchronously.
generate
public @NonNull AsyncTask<Bitmap, Void, Palette> generate(@NonNull Palette.PaletteAsyncListener listener)
Generate the Palette asynchronously. The provided listener's onGenerated method will be called with the palette when generated.
maximumColorCount
public @NonNull Palette.Builder maximumColorCount(int colors)
Set the maximum number of colors to use in the quantization step when using a android.graphics.Bitmap as the source.
Good values for depend on the source image type. For landscapes, good values are in the range 10-16. For images which are largely made up of people's faces then this value should be increased to ~24.
resizeBitmapArea
public @NonNull Palette.Builder resizeBitmapArea(int area)
Set the resize value when using a android.graphics.Bitmap as the source. If the bitmap's area is greater than the value specified, then the bitmap will be resized so that its area matches area. If the bitmap is smaller or equal, the original is used as-is.
This value has a large effect on the processing time. The larger the resized image is, the greater time it will take to generate the palette. The smaller the image is, the more detail is lost in the resulting image and thus less precision for color selection.
| Parameters | |
|---|---|
int area |
the number of pixels that the intermediary scaled down Bitmap should cover, or any value <= 0 to disable resizing. |
public @NonNull Palette.BuilderresizeBitmapSize(int maxDimension)
Set the resize value when using a android.graphics.Bitmap as the source. If the bitmap's largest dimension is greater than the value specified, then the bitmap will be resized so that its largest dimension matches maxDimension. If the bitmap is smaller or equal, the original is used as-is.
| Parameters | |
|---|---|
int maxDimension |
the number of pixels that the max dimension should be scaled down to, or any value <= 0 to disable resizing. |