相关疑难解决方法(0)

如何从网络映像中获取Flutter Uint8List?

我正在尝试将网络映像转换为文件,并且该文件的第一部分是将其转换为Uint8List。这是我对其中的一张资产图片执行的操作...

      final ByteData bytes = await rootBundle.load('assests/logo');
      final Uint8List list = bytes.buffer.asUint8List();

      final tempDir = await getTemporaryDirectory();
      final file = await new File('${tempDir.path}/image.jpg').create();
      file.writeAsBytesSync(list);
Run Code Online (Sandbox Code Playgroud)

我该怎么做 Image.network(imageUrl.com/image)

byte image file dart flutter

6
推荐指数
3
解决办法
5261
查看次数

Flutter - 如何将 NetworkImage 转换为 ui.Image?

我需要将 NetworkImage 转换为 ui.Image。我尝试使用此问题给出的解决方案进行一些调整,但它不起作用。

有人可以帮助我吗?

 Uint8List yourVar;
 ui.Image image;
    final DecoderCallback callback =
        (Uint8List bytes, {int cacheWidth, int cacheHeight}) async {
      yourVar = bytes.buffer.asUint8List();
      var codec = await instantiateImageCodec(bytes,
          targetWidth: cacheWidth, targetHeight: cacheHeight);
      var frame = await codec.getNextFrame();
      image = frame.image;
      return image;
    };
    ImageProvider provider = NetworkImage(yourImageUrl);
    provider.obtainKey(createLocalImageConfiguration(context)).then((key) {
      provider.load(key, callback);
    });
Run Code Online (Sandbox Code Playgroud)

image flutter

2
推荐指数
1
解决办法
1006
查看次数

标签 统计

flutter ×2

image ×2

byte ×1

dart ×1

file ×1