How to get an image from a canvas drawn with CustomPainter?
You don't need to pass the PictureRecorder
to the canvas in the CustomPainter
paint
method. Instead you can call paint directly with a different canvas that has a picture recorder. For Example:
Future<Image> getImage() async {final PictureRecorder recorder = PictureRecorder();myPainter.paint(Canvas(recorder), mySize);final Picture picture = recorder.endRecording();return await picture.toImage(width, height);}