9

I have a Flutter canvas , and I'd like to save that canvas as a bitmap image (e.g. PNG, but any common bitmap format will do). What's the best way to get the bits out of a canvas, converted to a bitmap image format?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
  • it has been [implemented](https://github.com/flutter/engine/commit/b6f466b344108731e26dbdf44a11a3c98d70f696), you can now follow all the Collin's steps. – RX Labz Apr 09 '18 at 17:11
  • This answer might help https://stackoverflow.com/questions/50320479/flutter-how-would-one-save-a-canvas-custompainter-to-an-image-file/52279202#answer-52279202 – Aravind Vemula Sep 11 '18 at 15:52
  • https://stackoverflow.com/questions/50320479/flutter-how-would-one-save-a-canvas-custompainter-to-an-image-file/52279202#answer-52279202 this answer may help – Aravind Vemula Sep 11 '18 at 15:53

1 Answers1

12
  1. Create a PictureRecorder.
  2. Create a Canvas with your PictureRecorder and draw stuff.
  3. Call endRecording() on the PictureRecorder to get a Picture.
  4. Call toImage() on the Picture.
  5. Call toByteData() on the Image.
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Collin Jackson
  • 110,240
  • 31
  • 221
  • 152