我有图像的网络网址,我需要得到Uint8List。如何转换?我在类似的问题中检查答案,但这些方法不起作用。How to get a Flutter Uint8List from a Network Image?
发布于 2020-01-27 15:16:46
Uint8List yourVar;
final DecoderCallback callback = (Uint8List bytes, {int cacheWidth, int cacheHeight}) {
yourVar = bytes.buffer.asUint8List();
return instantiateImageCodec(bytes, targetWidth: cacheWidth, targetHeight: cacheHeight);
};
ImageProvider provider = NetworkImage(yourImageUrl);
provider.obtainKey(createLocalImageConfiguration(context)).then((key) {
provider.load(key, callback);
});
发布于 2020-07-07 23:14:05
试试这个:
Uint8List bytes = (await NetworkAssetBundle(Uri.parse(url)).load(url))
.buffer
.asUint8List();
发布于 2021-03-29 10:41:58
这对我来说很有用:
import 'dart:typed_data';
import 'package:flutter/services.dart';
//Get the image from the URL and then convert it to Uint8List
Uint8List bytes = (await NetworkAssetBundle(Uri.parse('https://some_image_url.png'))
.load('https://some_image_url.png'))
.buffer
.asUint8List();
https://stackoverflow.com/questions/59894880
复制相似问题