toPngBytes method
Implementation
Future<Uint8List?> toPngBytes({double pixelRatio = 3, Color? background}) async {
if (canvasSize.isEmpty) return null;
final ui.PictureRecorder recorder = ui.PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.scale(pixelRatio);
if (background != null) canvas.drawRect(Offset.zero & canvasSize, Paint()..color = background);
for (final USignatureStroke stroke in _strokes) {
_USignaturePainter.paintStroke(canvas, stroke);
}
final ui.Image image = await recorder.endRecording().toImage((canvasSize.width * pixelRatio).round(), (canvasSize.height * pixelRatio).round());
final ByteData? data = await image.toByteData(format: ui.ImageByteFormat.png);
image.dispose();
return data?.buffer.asUint8List();
}