imageToUint8List function

Future<Uint8List> imageToUint8List(
  1. Image image
)

Converts a Image to a Uint8List representation.

This function takes a Image and converts it to a Uint8List containing the raw RGBA data of the image.

Parameters:

  • image: The source image to be converted. Can be null.

Returns: A Future that resolves to a Uint8List containing the raw RGBA data of the image. If the input image is null or conversion fails, returns an empty Uint8List.

Implementation

Future<Uint8List> imageToUint8List(final Image image) async {
  final ByteData? data = await image.toByteData(
    format: ImageByteFormat.rawRgba,
  );
  return data?.buffer.asUint8List() ?? Uint8List(0);
}