flutter - 将应用程序中创建的图像(使用画家插件)保存到设备本地图库
问题描述
我尝试了几种方法,但我是 Flutter 和移动开发的新手,所以我不太熟悉整个环境。
我在这里使用了画家示例https://pub.dev/packages/painter/example
我使用此代码尝试保存图像文件。
image_file.dart
import 'dart:ui';
class ImageFile {
var imageFile;
get getImageFile => this.imageFile;
set setImageFile(var imageFile) => this.imageFile = imageFile;
ImageFile({required this.imageFile});
}
然后我创建了类的实例并分配了
Image.memory(snapshot.data)
作为
ImageFile(imageFile: Image.memory(snapshot.data!));
到它,以便我可以全局访问它,然后我创建了一个方法来保存 ImageFile 对象中的图像并将其附加到一个 floatingActionButton。
void _saveFileImage(path) async {
String path = (await getApplicationDocumentsDirectory()).path;
GallerySaver.saveImage(path);
}
floatingActionButton: FloatingActionButton(
onPressed: () {
if (imageFile!.getImageFile != null) {
_saveFileImage(imageFile!.getImageFile);
} else {
debugPrint("null object");
}
}, //_saveImage(imageFile),
tooltip: 'Save to gallery',
child: const Icon(Icons.save_alt_outlined),
),
如果您对如何使用画师包中的 gallery_saver 包或 image_gallery_saver 包有任何想法,请提供帮助。
image_file.dart - https://codeshare.io/Pdm0lY
main.dart - https://codeshare.io/78gMbL
谢谢
解决方案
推荐阅读
- qt - 未调用模型中的 QListView moveRow()
- c# - Azure Functions 依赖注入 - 注册自定义服务
- git - git diff:显示分支名称而不是提交哈希
- c++ - 如何在 C++ 中编写 MATLAB fix(X) 函数?
- python - 如何计算类别效用
- android - 如何等待协程 Dispatch.IO 数据库查询完成以填充 RecyclerView
- javascript - ES6 在 API 请求中更改为固定值
- linux - Linux正则表达式命令
- java - 如何将 String 转换为它所代表的通用信息?
- c - 映射大文件,然后使用 cgroups 限制内存