PaletteGenerator class
A class to extract prominent colors from an image for use as user interface colors.
To create a new PaletteGenerator, use the asynchronous PaletteGenerator.fromImage static function.
A number of color paletteColors with different profiles are chosen from the image:
You may add your own target palette color types by supplying them to the
targets
parameter for PaletteGenerator.fromImage.
In addition, the population-sorted list of discovered colors is available, and a paletteColors list providing contrasting title text and body text colors for each palette color.
The palette is created using a color quantizer based on the Median-cut algorithm, but optimized for picking out distinct colors rather than representative colors.
The color space is represented as a 3-dimensional cube with each dimension being one component of an RGB image. The cube is then repeatedly divided until the color space is reduced to the requested number of colors. An average color is then generated from each cube.
What makes this different from a median-cut algorithm is that median-cut divides cubes so that all of the cubes have roughly the same population, where the quantizer that is used to create the palette divides cubes based on their color volume. This means that the color space is divided into distinct colors, rather than representative colors.
See also:
- PaletteColor, to contain various pieces of metadata about a chosen palette color.
- PaletteTarget, to be able to create your own target color types.
- PaletteFilter, a function signature for filtering the allowed colors in the palette.
- Mixed-in types
Constructors
-
PaletteGenerator.fromColors(List<
PaletteColor> paletteColors, {List<PaletteTarget> targets = const <PaletteTarget>[]}) - Create a PaletteGenerator from a set of paletteColors and targets.
Properties
-
colors
→ Iterable<
Color> -
Returns a list of colors in the paletteColors, sorted from most
dominant to least dominant color.
no setter
- darkMutedColor → PaletteColor?
-
Returns a muted and dark color from the palette. Might be null if an
appropriate target color could not be found.
no setter
- darkVibrantColor → PaletteColor?
-
Returns a dark and vibrant color from the palette. Might be null if an
appropriate target color could not be found.
no setter
- dominantColor → PaletteColor?
-
The dominant color (the color with the largest population).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- lightMutedColor → PaletteColor?
-
Returns a muted and light color from the palette. Might be null if an
appropriate target color could not be found.
no setter
- lightVibrantColor → PaletteColor?
-
Returns a light and vibrant color from the palette. Might be null if an
appropriate target color could not be found.
no setter
- mutedColor → PaletteColor?
-
Returns a muted color from the palette. Might be null if an appropriate
target color could not be found.
no setter
-
paletteColors
→ List<
PaletteColor> -
The list of PaletteColors that make up the palette, sorted from most
dominant color to least dominant color.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
selectedSwatches
→ Map<
PaletteTarget, PaletteColor> -
Provides a map of the selected paletteColors for each target in targets.
final
-
targets
→ List<
PaletteTarget> -
The list of targets that the palette uses for custom color selection.
final
- vibrantColor → PaletteColor?
-
Returns a vibrant color from the palette. Might be null if an appropriate
target color could not be found.
no setter
Methods
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromByteData(
EncodedImage encodedImage, {Rect? region, int maximumColorCount = _defaultCalculateNumberColors, List< PaletteFilter> filters = const <PaletteFilter>[avoidRedBlackWhitePaletteFilter], List<PaletteTarget> targets = const <PaletteTarget>[]}) → Future<PaletteGenerator> - Create a PaletteGenerator asynchronously from encoded image ByteData, width, and height. These parameters are packed in EncodedImage.
-
fromImage(
Image image, {Rect? region, int maximumColorCount = _defaultCalculateNumberColors, List< PaletteFilter> filters = const <PaletteFilter>[avoidRedBlackWhitePaletteFilter], List<PaletteTarget> targets = const <PaletteTarget>[]}) → Future<PaletteGenerator> - Create a PaletteGenerator from an dart:ui.Image asynchronously.
-
fromImageProvider(
ImageProvider< Object> imageProvider, {Size? size, Rect? region, int maximumColorCount = _defaultCalculateNumberColors, List<PaletteFilter> filters = const <PaletteFilter>[avoidRedBlackWhitePaletteFilter], List<PaletteTarget> targets = const <PaletteTarget>[], Duration timeout = const Duration(seconds: 15)}) → Future<PaletteGenerator> - Create a PaletteGenerator from an ImageProvider, like FileImage, or AssetImage, asynchronously.