将UINT8列表图像数据转换为ImageGallerySaver保存文件字符串
如何转换的Uint8List imagedata以使用saveFile命令保存它,该命令需要一个字符串将UINT8列表图像数据转换为ImageGallerySaver保存文件字符串,image,flutter,file,Image,Flutter,File,如何转换的Uint8List imagedata以使用saveFile命令保存它,该命令需要一个字符串 TextButton( onPressed: () { _imageFile = null; screenshotController .capture() .then((U
TextButton(
onPressed: () {
_imageFile = null;
screenshotController
.capture()
.then((Uint8List image) async {
//print("Capture Done");
setState(() {
_imageFile = image;
});
final result = await ImageGallerySaver.saveFile();
print("File Saved to Gallery");
}).catchError((onError) {
print(onError);
});
我找到了一个解决方案:
TextButton(
onPressed: () {
_imageFile = null;
screenshotController
.capture()
.then((Uint8List image) async {
//print("Capture Done");
String dir =
(await getApplicationDocumentsDirectory()).path;
File file = File("$dir/" +
DateTime.now().millisecondsSinceEpoch.toString() +
".png");
await file.writeAsBytes(image);
setState(() {
_imageFile = image;
});
final result =
await ImageGallerySaver.saveFile(file.path);
print("File Saved to Gallery");
}).catchError((onError) {
print(onError);
});
},
child: Icon(Icons.change_history),
), // Thi