【发布时间】:2023-03-10 08:58:01
【问题描述】:
我正在使用flutter_inappwebview 截取网页截图。屏幕截图为Uint8List 格式。我想将其更改为File,以便可以将其保存在我的服务器中。
【问题讨论】:
标签: flutter
我正在使用flutter_inappwebview 截取网页截图。屏幕截图为Uint8List 格式。我想将其更改为File,以便可以将其保存在我的服务器中。
【问题讨论】:
标签: flutter
这是一个示例,path 是您的图像的完整路径,img 是您的 Uint8List:
File newFile = await File(path).writeAsBytes(img);
【讨论】:
getApplicationDocumentsDirectory() is from path_provider package.
onPressed: () async {
final result = await webView.takeScreenshot();
final directory = (await getApplicationDocumentsDirectory()).path; // to get path of the file
String fileName = DateTime.now().toIso8601String(); // the name needs to be unique every time you take a screenshot
var path = '$directory/$fileName.png';
File image = await File(path).writeAsBytes(result); // thanks to the answer above by @Guillaume Roux
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Image.file(image),
);
},
);
},
【讨论】: