imageToBytes method

Future<Uint8List?> imageToBytes(
  1. Image image
)

Convert ui.Image to raw bytes for platform channel transfer

This can be used to send frames to native code for actual MediaStream creation.

Implementation

Future<Uint8List?> imageToBytes(ui.Image image) async {
  try {
    final byteData =
        await image.toByteData(format: ui.ImageByteFormat.rawRgba);
    return byteData?.buffer.asUint8List();
  } catch (e) {
    debugPrint('VirtualStreamSource: Failed to convert image to bytes: $e');
    return null;
  }
}