toImage method

Future<ByteData?> toImage({
  1. int width = 512,
  2. int height = 256,
  3. Color? color,
  4. Color? background,
  5. double? size,
  6. double? maxSize,
  7. double? border,
  8. ImageByteFormat format = ImageByteFormat.png,
  9. bool fit = true,
})

Exports data to raw image.

If fit is enabled, the path will be normalized and scaled to fit given width and height.

Implementation

Future<ByteData?> toImage({
  int width: 512,
  int height: 256,
  Color? color,
  Color? background,
  double? size,
  double? maxSize,
  double? border,
  ImageByteFormat format: ImageByteFormat.png,
  bool fit: true,
}) async {
  final image = await toPicture(
    width: width,
    height: height,
    color: color,
    background: background,
    size: size,
    maxSize: maxSize,
    border: border,
    fit: fit,
  )?.toImage(width, height);

  if (image == null) {
    return null;
  }

  return image.toByteData(format: format);
}