imageFromBytes function Assets and loading

Future<Image> imageFromBytes(
  1. Uint8List bytes
)

Decodes an encoded image (PNG, JPEG, etc.) from raw bytes.

Uses dart:ui's built-in image codecs. Throws if the bytes can't be decoded as an image.

Implementation

Future<ui.Image> imageFromBytes(Uint8List bytes) async {
  final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
  final codec = await ui.instantiateImageCodecFromBuffer(buffer);
  final frame = await codec.getNextFrame();
  return frame.image;
}