我正在使用flutter_inappwebview来截取网页的截图。截图为Uint8List格式。我想把它改成File,这样我就可以把它保存在我的服务器上。
发布于 2021-03-04 15:28:53
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),
);
},
);
},发布于 2021-03-04 06:43:16
以下是一个示例,其中path是图像的完整路径,并对Uint8List执行img操作
File newFile = await File(path).writeAsBytes(img);https://stackoverflow.com/questions/66463576
复制相似问题