ui.Image

读取 assets 中的图片

  Future _readImage(String imgPath, {int w = 44, int h = 44}) async {
    dart_ui.FrameInfo? frameInfo;
    ByteData byteData = await rootBundle.load(imgPath);
    dart_ui.Codec codec = await dart_ui.instantiateImageCodec(
        byteData.buffer.asUint8List(),
        targetWidth: w,
        targetHeight: h);
    frameInfo = await codec.getNextFrame();
    setState(() {
      _uiImage = frameInfo?.image;
    });
  }

你可能感兴趣的:(ui.Image)