writeToolExportPng function

Future<File> writeToolExportPng(
  1. Image image
)

Encode image to a PNG temp file. Used by tool screens (crop, draw) when the user applies an edit. The PNG offload to a compute() isolate is parked behind Phase 6.

Implementation

Future<io.File> writeToolExportPng(ui.Image image) async {
  final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  final bytes = byteData!.buffer.asUint8List();
  final tmp = await getTemporaryDirectory();
  final stamp = clock.now().microsecondsSinceEpoch;
  final out = io.File(p.join(tmp.path, 'compose_$stamp.png'));
  await out.writeAsBytes(bytes, flush: true);
  return out;
}