0

I am trying to save ui.Image into device gallery, to do so I have to convert ui.Image.toByteData which takes so much time. Is there a way to save image to gallery without using ui.Image.toByteData? Following is my code.

  final recorder = ui.PictureRecorder();
  Canvas canvas = Canvas(recorder);
  final size = Size(4902, 3000);
  painter.paint(canvas, size);
  final picture = recorder.endRecording();
  final img = await picture.toImage(4902, 3000);
  var bytes = await img.toByteData(format: ui.ImageByteFormat.png);//this line takes upto 25 seconds to execute
  Uint8List pngBytes = bytes.buffer.asUint8List();

  final result = await ImageGallerySaver.saveImage(
      Uint8List.fromList(pngBytes),
      quality: 80,
      name: 'canvas_image_${i + 1}_'+DateTime.now().toString());
D. Islam
  • 56
  • 5

0 Answers0