decodeImageFromPixels function

void decodeImageFromPixels (Uint8List pixels, int width, int height, PixelFormat format, ImageDecoderCallback callback, { int rowBytes, int targetWidth, int targetHeight })

Convert an array of pixel values into an Image object.

pixels is the pixel data in the encoding described by format.

rowBytes is the number of bytes consumed by each row of pixels in the data buffer. If unspecified, it defaults to width multiplied by the number of bytes per pixel in the provided format.

The targetWidth and targetHeight arguments specify the size of the output image, in image pixels. If they are not equal to the intrinsic dimensions of the image, then the image will be scaled after being decoded. If exactly one of these two arguments is specified, then the aspect ratio will be maintained while forcing the image to match the other given dimension. If neither is specified, then the image maintains its real size.

Implementation

void decodeImageFromPixels(
  Uint8List pixels,
  int width,
  int height,
  PixelFormat format,
  ImageDecoderCallback callback,
  {int rowBytes, int targetWidth, int targetHeight}
) {
  final _ImageInfo imageInfo = _ImageInfo(width, height, format.index, rowBytes);
  final Future<Codec> codecFuture = _futurize(
    (_Callback<Codec> callback) => _instantiateImageCodec(pixels, callback, imageInfo, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
  );
  codecFuture.then((Codec codec) => codec.getNextFrame())
      .then((FrameInfo frameInfo) => callback(frameInfo.image));
}