instantiateImageCodec method

Future<Codec> instantiateImageCodec (
  1. Uint8List bytes,
  2. {int cacheWidth,
  3. int cacheHeight,
  4. bool allowUpscaling: false}

Calls through to dart:ui from ImageCache.

The cacheWidth and cacheHeight parameters, when specified, indicate the size to decode the image to.

Both cacheWidth and cacheHeight must be positive values greater than or equal to 1, or null. It is valid to specify only one of cacheWidth and cacheHeight with the other remaining null, in which case the omitted dimension will be scaled to maintain the aspect ratio of the original dimensions. When both are null or omitted, the image will be decoded at its native resolution.

The allowUpscaling parameter determines whether the cacheWidth or cacheHeight parameters are clamped to the intrinsic width and height of the original image. By default, the dimensions are clamped to avoid unnecessary memory usage for images. Callers that wish to display an image above its native resolution should prefer scaling the canvas the image is drawn into.


Future<ui.Codec> instantiateImageCodec(Uint8List bytes, {
  int cacheWidth,
  int cacheHeight,
  bool allowUpscaling = false,
}) {
  assert(cacheWidth == null || cacheWidth > 0);
  assert(cacheHeight == null || cacheHeight > 0);
  assert(allowUpscaling != null);
  return ui.instantiateImageCodec(
    targetWidth: cacheWidth,
    targetHeight: cacheHeight,
    allowUpscaling: allowUpscaling,