所以我想存储我的图像到列表,但我不能将它转换为Uint8list,在flutter中有一种方法可以使用另一个选项,如RootBundle?
为什么不使用RootBundler ??问题是RootBundle需要在资产部分下的Pubspec.yaml上声明,但我要转换的图像在应用程序临时目录中,这是我无法更改的,因此RootBundle无法访问并始终抛出资产为空(这不是),因为它没有在pubspec.yaml中声明
static Future pickImage(PickType type) async {
try {
var photo = await ImagePicker().pickImage(
source:
type == PickType.Camera ? ImageSource.camera : ImageSource.gallery,
imageQuality: 80,
);
var photosPicked;
print(photo!.name);
Directory tempDir = await getTemporaryDirectory();
print(tempDir.path);
rootBundle
.load('${tempDir.path}/${photo.name}')
.then((value) => photosPicked = value);
return photosPicked;
} catch (e) {
print(e);
}
}发布于 2021-08-22 21:51:50
我是用ReadAsByte函数算出来的
static Future pickImage(PickType type) async {
try {
var photo = await ImagePicker().pickImage(
source:
type == PickType.Camera ? ImageSource.camera : ImageSource.gallery,
imageQuality: 80,
);
File imageFile = File(photo!.path);
Uint8List imageRaw = await imageFile.readAsBytes();
return imageRaw;
} catch (e) {
print(e);
}
}https://stackoverflow.com/questions/68720430
复制相似问题