flutter - 如何在 Flutter 中截屏?
问题描述
有没有一种方法或包可以帮助截取全屏屏幕截图,或者包装的小部件屏幕截图,或者至少通过本机共享选项共享屏幕图片?
有一些包,我试过了,没有找到有用的包。
解决方案
RepaintBoundary就是你要找的 Widget,这个可以转换成图片。
例子:
Future<CaptureResult> captureImage() async {
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
final boundary = _boundaryKey.currentContext.findRenderObject() as RenderRepaintBoundary;
final image = await boundary.toImage(pixelRatio: pixelRatio);
final data = await image.toByteData(format: ui.ImageByteFormat.png);
return CaptureResult(data.buffer.asUint8List(), image.width, image.height);
}
final _boundaryKey = GlobalKey();
RepaintBoundary(
key: _boundaryKey,
child: Container(),// Your Widgets to be captured.
)
推荐阅读
- php - Laravel - 结合 {!! ... !!} 和asset('image/my.png') 结果资产代码打印不显示图像
- python - 决策树未捕获因变量的方差
- php - 隐藏 html 视频 url 源/将 Linux 文件夹限制为特定的 php 用户
- java - 在 IDE 上运行 JavaFX 11 导致在子模块的资源上找不到 URL 错误
- c# - 通过 Postman 在 Asp.net Core API 中发布数据时将值转换为类型时出错
- c# - 为什么垃圾收集、关闭和 lambda 禁用 prism 事件聚合器订阅?
- python - python 从txt文件ping ip地址
- typescript - 打字稿:访问祖父母类方法
- python - 在 pandas 数据帧上使用转换函数,向数据帧的每一行返回新值
- javascript - 刀片 laravel 中的总值之和