android - Flutter:在 Whatsapp 和 Facebook 共享图像时无法在预览中显示图像
问题描述
该图像可以在 Facebook Messenger 聊天中显示,但该图像无法在 Whatsapp 以及 Messenger 和 whatsapp 的预览图像中显示。知道我在哪里做错了吗?
Main.dart - 这是我捕获图像并将其保存到临时目录的位置。
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
var image = await boundary.toImage(pixelRatio: 3.0);
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.png').create();
await file.writeAsBytes(pngBytes);
final channel = const MethodChannel('channel:me.amanda.share/share');
channel.invokeMethod('shareFile', 'image.png');
MainActivity.java
private void shareFile(String path) {
try{
File imageFile = new File(this.getCacheDir(), path);
Uri contentUri = FileProvider.getUriForFile(this, "me.amanda.share",
imageFile);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setData(contentUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
this.startActivity(Intent.createChooser(shareIntent, "Share image
using"));
}
catch (Exception ex){
//android.widget.Toast.makeText(this, ex.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
文件路径.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="image" path="."/>
</paths>
解决方案
对不起,伙计们,这是一个非常愚蠢的错误。图像是二维码,二维码的背景是透明的。因此,我应该将 qr 图像包装到 Container() 小部件中,并将容器设置为白色,RepaintBoundary 可以使用 QR 码捕获整个容器。我没有注意到预览图像和信使是黑暗的。
这是一个例子。
hasValue ? Container(
height: 230.0,
color: Colors.white,
margin: EdgeInsets.all(10.0),
child: Center(
child: RepaintBoundary(
key: globalKey,
child: Container(
color: Colors.white,
child: QrImage(
data: !isScan ? _dataBarcodeString : trimBarcodeValue,
size: 200.0,
),
)
),
),
推荐阅读
- javascript - js2py.internals.simplex.JsException:ReferenceError:未定义音频
- python - Flask、Postman 和 Mysql 多字段插入问题
- sql - 拆分逗号分隔的字符串并插入到具有相应 PK 的新表中
- android - 在本机端操作 BufferQueue
- python - 我在数据集中有年龄变量,我想将变量分类为“年轻”、“成人”、“老”
- jsp - 此页面无法显示/•确保网址http://localhost:8080正确
- string - 回车惹麻烦
- css - 带有输入占位符的字体 Awesome5
- ios - CallKit:将号码添加到 CXCallDirectoryProvider 的阻止列表中
- python - 如何在 django 模型中保存用户特定的测验答案?