将Uint8List转换为文件 [英] Convert Uint8List to File

查看:223
本文介绍了将Uint8List转换为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用效果很好的Image Picker网站.我可以在 Image.memory()中显示图像,但是此图像的格式为Uintlist8.要以存储方式保存格式为 File 的文件,我的问题是如何在 Firebase Storage 中保存图像.

I'm using Image Picker web which works well. I can display image in Image.memory(), but this image in format Uintlist8. For save in storage need format File, my issue is how to save an image in 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);
  });
 }
}

这篇关于将Uint8List转换为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆