artifactFromImage function

Future<Artifact> artifactFromImage(
  1. Image image
)

Creates a Artifact from a Image.

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

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

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

Returns a Future<Artifact> representing the image data. The returned Artifact 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 Artifact.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

Future<Artifact> artifactFromImage(final Image image) async {
  final Uint8List uint8List = await imageToUint8List(image);
  return Artifact.fromUint8List(uint8List, image.width);
}