【发布时间】:2020-11-01 05:53:14
【问题描述】:
我正在尝试将从画布生成的 ByteData 图像保存到设备 download 文件夹中。但是,我只能使用下面的代码将其保存到我的应用程序 android/data/ 目录中......
Future<void> saveImage(
String fileName,
ByteData image,
) async {
final directoryName = "Generated";
Directory directory = await getExternalStorageDirectory();
String path = directory.path;
await Directory('$path/$directoryName').create(recursive: true);
File('$path/$directoryName/$fileName.png').writeAsBytesSync(image.buffer.asInt8List());
}
但是,用户进入这个深层目录只是为了获取图像并不方便,所以我想将它保存到下载目录但我不知道如何。我尝试了几种方法,但我不断收到权限错误。例如使用下面的代码 (downloads_path_provider)...
Directory directory = await DownloadsPathProvider.downloadsDirectory;
String path = directory.path;
File('$path/$fileName.png').writeAsBytesSync(image.buffer.asInt8List());
PS。如果有办法将它保存在手机图库中会显示的某个地方会更好
【问题讨论】:
标签: flutter