【发布时间】:2020-06-05 03:34:14
【问题描述】:
我需要将 NetworkImage 转换为 ui.Image。 我尝试使用此question 中的给定解决方案并进行一些调整,但它不起作用。
有人可以帮助我吗?
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);
});
【问题讨论】:
-
为什么不直接使用http包和
decodeImageFromList顶层函数呢? -
用http我可以缓存图片吗?我询问了 NetworkImage,因为我打算使用 CachedNetworkImageProvider。