fromImage static method

Future<Matrix> fromImage(
  1. Image image
)

Creates a Matrix from a ui.Image.

This factory constructor takes a ui.Image object and transforms it into a Matrix representation. The process involves two main steps:

  1. Converting the image to a Uint8List using imageToUint8List.
  2. Creating a Matrix from the Uint8List using Matrix.fromUint8List.

image The ui.Image object to be converted. This should be a valid, non-null image object.

Returns a Future<Matrix> representing the image data. The returned Matrix will have the same width as the input image, and its height will be determined by the length of the Uint8List and the width.

Throws an exception if imageToUint8List fails to convert the image or if Matrix.fromUint8List encounters an error during matrix creation.

Note: This constructor is asynchronous due to the imageToUint8List operation. Ensure to await its result when calling.

Implementation

static Future<Matrix> fromImage(final ui.Image image) async {
  final Uint8List uint8List = await imageToUint8List(image);
  return Matrix.fromUint8List(uint8List, image.width);
}