flutter - 将 Uint8List 转换为文件
问题描述
我正在使用运行良好的图像选择器网络。我可以在 中显示图像Image.memory()
,但此图像以 Uintlist8 格式显示。为了保存在存储中需要格式File
,我的问题是如何在Firebase Storage中保存图像。
网络图像选择器:
class _SecondPageState extends State<SecondPage> {
final _formkey = GlobalKey<FormState>();
Uint8List _image;
getImage() async {
Uint8List tempImg = await ImagePickerWeb.getImage(asUint8List: true);
if (tempImg != null) {
setState(() {
_image = tempImg;
});
}
}
解决方案
请试试 ....
final _formkey = GlobalKey<FormState>();
Uint8List _image;
getImage() async {
Uint8List tempImg = await ImagePickerWeb.getImage(asUint8List: true);
if (tempImg != null) {
setState(() {
_image = tempImg;
final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.jpg').create();
file.writeAsBytesSync(_image);
});
}
}
推荐阅读
- excel - 我们如何使用 VBA 代码登录 Outlook?
- julia - 如何定义一个 Vector 以使 Julia 中的所有元素都具有相同的类型?
- angular - 使用自定义模块应用primeng
- python - 使用 Python 捕获 HTML 文本的正则表达式
- php - 没有警报消息,Ajax 成功不起作用
- redis - 我可以为 redis zset 定义自定义比较函数吗?
- java - 动态(重新)加载服务提供者模块
- d3.js - 在应用过渡之前停止绘制第一条路径的正确方法是什么?
- python - 如何使用 Python 从 Google 表格中获取特定的单元格值以用于不和谐机器人?
- python - 如何从python中的字符串中删除多次出现?