saveToFile method

Future saveToFile(
  1. String filePath
)

将图像保存到指定文件路径

filePath 文件路径 返回一个Future对象

Implementation

Future saveToFile(String filePath) async {
  ui.Image image = await _toImage();
  var bytes = await (image.toByteData(format: ui.ImageByteFormat.png)
      as FutureOr<ByteData>);
  Uint8List ul = bytes.buffer.asUint8List();
  File file = File(filePath);
  file.openWrite();
  file.writeAsBytesSync(ul);
}