toPicture method
Exports data to Picture.
If fit
is enabled, the path will be normalized and scaled to fit given width
and height
.
Implementation
Picture? toPicture({
int width = 512,
int height = 256,
Color? color,
Color? background,
double? strokeWidth,
double? maxStrokeWidth,
HandSignatureDrawer? drawer,
double border = 0.0,
bool fit = false,
}) {
if (!isFilled) {
return null;
}
final outputArea =
Rect.fromLTWH(0.0, 0.0, width.toDouble(), height.toDouble());
params ??= SignaturePaintParams(
color: Colors.black,
strokeWidth: 1.0,
maxStrokeWidth: 10.0,
);
maxStrokeWidth ??= params!.maxStrokeWidth;
final bounds = PathUtil.boundsOf(_offsets, radius: maxStrokeWidth * 0.5);
final data = PathUtil.fillData(
_cubicLines,
outputArea,
bound: fit
? bounds
: bounds.size
.scaleToFit(Size(width.toDouble(), height.toDouble()))
.toRect(),
border: maxStrokeWidth + border,
);
int i = 0;
final painter = PathSignaturePainter(
paths: paths
.map((e) => CubicPath(setup: e.setup).._lines.addAll(data[i++]))
.toList(),
drawer: drawer ??
ArcSignatureDrawer(
color: color ?? params!.color,
width: strokeWidth ?? params!.strokeWidth,
maxWidth: maxStrokeWidth,
),
);
final recorder = PictureRecorder();
final canvas = Canvas(
recorder,
outputArea,
);
if (background != null) {
canvas.drawColor(background, BlendMode.src);
}
painter.paint(canvas, outputArea.size);
return recorder.endRecording();
}