decodeImageData static method

Future<Image?> decodeImageData(
  1. Uint8List data, {
  2. int width = 100,
  3. int height = 100,
})

Decodes image data represented as a Uint8List into a ui.Image asynchronously.

Parameters

  • IN data A Uint8List representing the raw image data to be decoded.
  • IN width Optional parameter specifying the desired width of the resulting image. Default value is 100.
  • IN height Optional parameter specifying the desired height of the resulting image. Default value is 100.

Returns

  • A Future that completes with the decoded ui.Image object, or null if decoding fails.

The decoding process is asynchronous, so the returned Future will complete when the image decoding is finished.

Implementation

static Future<ui.Image?> decodeImageData(
  final Uint8List data, {
  final int width = 100,
  final int height = 100,
}) async {
  final Completer<ui.Image?> completer = Completer<ui.Image?>();

  ui.decodeImageFromPixels(data, width, height, ui.PixelFormat.rgba8888, (
    final ui.Image img,
  ) async {
    completer.complete(img);
  });

  return completer.future;
}