flutter - Flutter 如何通过分享插件分享文件图片
问题描述
Hello and thank you in advance!
我正在处理图像编辑。我可以从图像选择器中选择图像并在 drawstringdrawstring 的帮助下重写它。我可以将图像保存在我的文档目录中。我想通过 Share 插件从 documentDirectory 路径分享我的图像。但是,我收到一个错误。
代码和错误详情如下所示。
代码:
FlatButton(
child: Text("Apply Watermark Over Image"),
onPressed: () async {
final image1 = ui.decodeImage(_originalImage.readAsBytesSync());
ui.drawString(image1, ui.arial_24, 300, 400, 'Hello And thank you');
final documentDirectory = await getApplicationDocumentsDirectory();
final file = new File(p.join(documentDirectory.path, "merged_image.jpg"));
file.writeAsBytesSync(ui.encodeJpg(image1));
// I HAVE THE IMAGE IN - documentDirectory.path "HERE I CANT SHARE THAT IMAGE"
final ByteData bytes = await rootBundle.load(documentDirectory.path);
await Share.file('esys image', 'esys.png', bytes.buffer.asUint8List(), 'image/png',
text: 'My optional text.');
},
)
我收到此错误:
[错误:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:无法加载资产:/data/user/0/com.photogranth.watermark/app_flutter
解决方案
对于共享文件图像,您可以使用这个flutter_share_file
FlatButton(
onPressed: () async {
Directory dir = await getApplicationDocumentsDirectory();
File testFile = new File("${dir.path}/image.png");
FlutterShareFile.shareImage(dir.path, "image.png", ShareFileType.image);
},
)
推荐阅读
- javascript - 检查数组 JavaScript 中是否存在字符串
- android - 我自己在 google maps sdk 中构建的图片
- javascript - AJAX 页面转换后禁止 Woocommerce 功能
- php - Symfony 表单通过 CollectionType 链接单选按钮
- calendar - Ext.ensible.cal.RecurrenceField 在 Ext.TabPanel 上不起作用
- shell - 在 Jenkins/groovy 的 shellscript 参数周围添加引号
- javascript - MongoDB聚合-如何向数组中的每个文档添加字段?
- python - 使用 google-api-python-client 时出错
- python - 无法使用 Selenium + Python 选择选项
- html - 从 excel 到 Outlook 的 HTML VBA 代码填充到: