如何解决如何在 Flutter 中导出屏幕的高分辨率图像?
如何在 Flutter 中以高分辨率将屏幕导出为图像或 PDF?是否可以使用用户输入作为图像导出带有背景图像和文本字段的容器?我试过这个解决方案 ("react-native paper / radio-button-group" lib),但分辨率太差了。我需要不同尺寸的屏幕,例如40x60cm、20x30cm 和 300Ddpi。
解决方法
您是否尝试过使用 pixelRatio
?
ui.Image image = await boundary.toImage(pixelRatio: 10);
,
尝试了 pixelRatio
并将其与更大的响应结合起来。没有 cacheWidth
- 它确实有效,至少对于 PNG 导出而言是这样。
但是请注意,pixelRatio
为 10 需要相当长的时间来捕获...
图像代码片段:
child: ClipRRect(
borderRadius: BorderRadius.circular(15),child: Image.file(
File(widget.myGroup.picture),width: MediaQuery.of(context).size.width,// NO cacheWidth:
// cacheWidth: MediaQuery.of(context).size.width,fit: BoxFit.fitWidth,),
_capturePng() 的代码片段:
Future<Uint8List> _capturePng() async {
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
if (boundary.debugNeedsPaint) {
print("Waiting for boundary to be painted.");
await Future.delayed(const Duration(milliseconds: 20));
return _capturePng();
}
var image = await boundary.toImage(pixelRatio: 10);
var byteData = await image.toByteData(format: ImageByteFormat.png);
return byteData.buffer.asUint8List();
}
(指this question here about screenshot with flutter on Stack Overflow)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。