【发布时间】:2020-02-19 17:02:19
【问题描述】:
有没有一种方法或包可以帮助截取全屏屏幕截图,或包装的小部件屏幕截图,或至少通过本机共享选项共享屏幕图片?
有一些包,我试过了,没找到有用的。
【问题讨论】:
-
请发布您使用的包,以避免任何多余的建议
有没有一种方法或包可以帮助截取全屏屏幕截图,或包装的小部件屏幕截图,或至少通过本机共享选项共享屏幕图片?
有一些包,我试过了,没找到有用的。
【问题讨论】:
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.
)
【讨论】: