簡體   English   中英

如何在 Flutter 中截屏?

[英]How to take screenshot in 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.
)

鏈接: capture_widget.dart

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM