loadUiImageResize static method

Future<Image> loadUiImageResize(
  1. String assetPath, {
  2. required int width,
  3. required int height,
  4. bool fromAsset = true,
})

Implementation

static Future<ui.Image> loadUiImageResize(
  String assetPath, {
  required int width,
  required int height,
  bool fromAsset = true,
}) async {
  final Uint8List data;
  if (fromAsset) {
    final byteData = await rootBundle.load(assetPath);
    data = byteData.buffer.asUint8List();
  } else {
    data = await _readFileByte(assetPath);
  }
  final codec = await ui.instantiateImageCodec(
    data,
    targetHeight: height,
    targetWidth: width,
    allowUpscaling: true,
  );
  final image = (await codec.getNextFrame()).image;
  return image;
}