5

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?

Thanks very much!

Seth Ladd
  • 95,521
  • 62
  • 179
  • 266
  • 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

10
  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. Oops, this isn't implemented yet. I filed an issue.
Collin Jackson
  • 97,818
  • 28
  • 207
  • 143
  • 1
    Was this method created? Do you have an example? – Eduardo Folly May 07 '18 at 02:37
  • 6
    If anyone lands on this answer looking to save any widget as a bitmap or png, support has been added for this (available on the dev channel). Full example at https://master-docs-flutter-io.firebaseapp.com/flutter/rendering/RenderRepaintBoundary/toImage.html – Andrei Tudor Diaconu May 15 '18 at 13:28