createImageFromPixels function
Creates a new Image from a Uint8List of pixel data.
This function takes a Uint8List containing the pixel data, the width,
and the height of the image, and creates a new Image from it.
Parameters:
pixels: The Uint8List containing the pixel data.width: The width of the image.height: The height of the image.
Returns: A Future that resolves to a Image created from the pixel data.
Implementation
Future<Image> createImageFromPixels(
final Uint8List pixels,
final int width,
final int height,
) async {
// Create a new Image from the modified pixels
final ImmutableBuffer buffer = await ImmutableBuffer.fromUint8List(pixels);
// Create a new Image from the modified pixels
final ImageDescriptor descriptor = ImageDescriptor.raw(
buffer,
width: width,
height: height,
pixelFormat: PixelFormat.rgba8888,
);
final Codec codec = await descriptor.instantiateCodec();
final FrameInfo frameInfo = await codec.getNextFrame();
return frameInfo.image;
}