zl程序教程

您现在的位置是:首页 >  其他

当前栏目

flutter Uint8List格式的图片和File格式图片的互相转换

转换flutter 图片 格式 File 互相
2023-09-14 09:04:29 时间

file格式图片转成Uint8List格式的图片

Uint8List imageByte;
imageByte = await widget.image.readAsBytes();
  //将回调拿到的Uint8List格式的图片转换为File格式
  SaveImage(Uint8List imageByte) async {
   //获取临时目录
    var tempDir = await getTemporaryDirectory();
    //生成file文件格式
    var file =
        await File('${tempDir.path}/image_${DateTime.now().millisecond}.jpg')
            .create();
            //转成file文件
    file.writeAsBytesSync(imageByte);
    print("${file.path}");
    setState(() {
      path = file.path;
      // turn(file);
      _imageUint8=imageByte;
    });
  }