我想将相机捕获的图像转换为base64,但似乎正在转换图像路径,而不是图像本身,请帮助我。
File file;
final picker = ImagePicker();
void _choose() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
file = File(pickedFile.path);
if (file != null) {
setState(() {
base64Encode(file.readAsBytesSync());
print(base64Encode(Image.file(file));
});
}
}
答案 0 :(得分:0)
您应该编码file.readAsBytesSync()
而不是Image.file(file)
。
File file;
final picker = ImagePicker();
void _choose() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
file = File(pickedFile.path);
if (file != null) {
setState(() {
base64Encode(file.readAsBytesSync());
print(base64Encode(file.readAsBytesSync());
});
}
}