toFlutterImage method
Returns a dart:io Image version of this PImage so that it
can be drawn with Flutter.
Implementation
Future<ui.Image> toFlutterImage() async {
if (_isFlutterImageDirty) {
final pixelsCodec = await ui.ImageDescriptor.raw(
await ui.ImmutableBuffer.fromUint8List(pixels.buffer.asUint8List()),
width: width.round(),
height: height.round(),
pixelFormat: ui.PixelFormat.rgba8888,
).instantiateCodec();
_flutterImage = (await pixelsCodec.getNextFrame()).image;
_isFlutterImageDirty = false;
}
return _flutterImage!;
}