toImage method

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

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? strokeWidth,
  double? maxStrokeWidth,
  double border = 32.0,
  ImageByteFormat format = ImageByteFormat.png,
  bool fit = false,
}) async {
  final image = await toPicture(
    width: width,
    height: height,
    color: color,
    background: background,
    strokeWidth: strokeWidth,
    maxStrokeWidth: maxStrokeWidth,
    border: border,
    fit: fit,
  )?.toImage(width, height);

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

  return image.toByteData(format: format);
}