fromUint8List method

Future<PaletteGenerator> fromUint8List (Uint8List imageData, { Rect region, int maximumColorCount, List<PaletteFilter> filters, List<PaletteTarget> targets })

Creates a PaletteGenerator from Uint8List image data asynchronously.

The region specifies the part of the image to inspect for color candidates. By default it uses the entire image. Must not be equal to Rect.zero, and must not be larger than the image dimensions.

The maximumColorCount sets the maximum number of colors that will be returned in the PaletteGenerator. The default is 16 colors.

The filters specify a lost of PaletteFilter instances that can be used to include certain colors in the list of colors. The default filter is an instance of AvoidRedBlackWhitePaletteFilter, which stays away from whites, blacks, and low-saturation reds.

The targets are a list of target color types, specified by creating custom PaletteTargets. By default, this is the list of targets in PaletteTarget.baseTargets.

The imageData must not be null.

Note:

  • You can use computeLuminance() method of dominantColor of type Color obtained from generated Palette.

Implementation

static Future<PaletteGenerator> fromUint8List(
  Uint8List imageData, {
  Rect region,
  int maximumColorCount,
  List<PaletteFilter> filters,
  List<PaletteTarget> targets,
}) async {
  assert(imageData != null);

  ui.Codec imageCodec = await ui.instantiateImageCodec(imageData);
  ui.FrameInfo imageFrame = await imageCodec.getNextFrame();
  ui.Image image = imageFrame.image;
  return await PaletteGenerator.fromImage(
    image,
    region: region,
    maximumColorCount: maximumColorCount,
    filters: filters,
    targets: targets,
  );
}