readPixels function
Reads image back as RGBA8.
Implementation
Future<RgbaPixels> readPixels(ui.Image image) async {
final data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
if (data == null) {
throw StateError('Could not read the image back.');
}
return RgbaPixels(
image.width,
image.height,
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
);
}