【发布时间】:2020-08-13 16:26:36
【问题描述】:
我正在尝试使用 image_picker 插件。我可以使用此插件将图像作为文件获取。我需要将此图像转换为字节并发送到 api。所以我尝试使用 dart:convert 将图像转换为字节字符串。现在,当我解码时,我得到一个 Uint8List 类型。如何将其转换为文件并显示在 Image.file() 中。我无法从这里开始。有人可以帮我解决这个问题吗?
考虑到我从 api 响应中得到这个 decodedBytes,我如何将它们转换为在 Image 小部件中显示
这是我目前尝试的代码。
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
imageURI = image;
final bytes = image.readAsBytesSync();
String img64 = base64Encode(bytes);
print(bytes);
print(img64);
final decodedBytes = base64Decode(img64);
print(decodedBytes);
//consider i am getting this decodedBytes i am getting from a api response, how can i convert them to display in a Image widget
});
我在使用 writeAsBytesSync() 时遇到此错误,
Unhandled Exception: FileSystemException: Cannot open file, path = 'decodedimg.png'
【问题讨论】: