【发布时间】:2019-10-04 14:53:24
【问题描述】:
在我的 Flutter 应用程序中,我使用 CustomPainter 来允许用户在屏幕上绘制他们的签名。我需要找到一种方法将其保存为图像。
PictureRecorder 在您能够按照previous StackOverflow answers 将PictureRecorder 对象传递到画布时效果很好:
final recorder = new PictureRecorder();
Canvas(recorder).drawSomething;
final picture = recorder.endRecording();
但是,当使用 CustomPainter 时,画布是 Paint() 函数的参数。
class myPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
drawToCanvas(canvas);
@override
bool shouldRepaint(CustomPainter old) {
return false;
}
总结一下:
如何从 CustomPainter 生成图像?
如果答案是使用 PictureRecorder,我怎样才能将记录器传递给画布?
【问题讨论】:
标签: image canvas dart flutter custom-painting