Flutter: How would one save a Canvas/CustomPainter to an image file?

前端 未结 2 398
时光说笑
时光说笑 2020-12-15 07:58

I am trying to collect a signature from the user and save it to an image. I have made it far enough that I can draw on the screen, but now I\'d like to click a button to sav

2条回答
  •  無奈伤痛
    2020-12-15 08:22

    You can capture the output of a CustomPainter with PictureRecorder. Pass your PictureRecorder instance to the constructor for your Canvas. The Picture returned by PictureRecorder.endRecording can then be converted to an Image with Picture.toImage. Finally, extract the image bytes using Image.toByteData.

    Here's an example: https://github.com/rxlabz/flutter_canvas_to_image

提交回复
热议问题