0

我正在尝试将 ui.Image 保存到设备库中,为此我必须转换 ui.Image.toByteData 这需要很长时间。有没有办法在不使用 ui.Image.toByteData 的情况下将图像保存到图库?以下是我的代码。

  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());
4

0 回答 0