toPicture method
Creates a Picture from this DrawableRoot.
Be cautious about not clipping to the ViewBox - you will be allowing your drawing to take more memory than it otherwise would, particularly when it is eventually rasterized.
Implementation
Picture toPicture({
Size? size,
bool clipToViewBox = true,
ColorFilter? colorFilter,
}) {
if (viewport.viewBox.width == 0) {
throw StateError('Cannot convert to picture with $viewport');
}
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, viewport.viewBoxRect);
if (colorFilter != null) {
canvas.saveLayer(null, Paint()..colorFilter = colorFilter);
} else {
canvas.save();
}
if (size != null) {
scaleCanvasToViewBox(canvas, size);
}
if (clipToViewBox == true) {
clipCanvasToViewBox(canvas);
}
draw(canvas, viewport.viewBoxRect);
canvas.restore();
return recorder.endRecording();
}