getBytesFromAsset static method

Future<Uint8List?> getBytesFromAsset({
  1. required String path,
  2. required int height,
  3. required int width,
})

Implementation

static Future<Uint8List?> getBytesFromAsset({
  required String path,
  required int height,
  required int width,
}) async {
  ByteData data = await rootBundle.load(path);
  ui.Codec codec = await ui.instantiateImageCodec(
    data.buffer.asUint8List(),
    targetHeight: height,
    targetWidth: width,
  );
  ui.FrameInfo fi = await codec.getNextFrame();

  final byteRes = await fi.image.toByteData(format: ui.ImageByteFormat.png);
  if (byteRes == null) {
    return null;
  }
  return byteRes.buffer.asUint8List();
}