【问题标题】:how to take screenshot of specific area on the screen in flutter?如何在颤动中截取屏幕上特定区域的屏幕截图?
【发布时间】:2021-12-27 05:59:26
【问题描述】:

我想提取屏幕上特定区域的图像?我有 x、y、高度和宽度。有谁知道我怎样才能做到这一点?

【问题讨论】:

  • 也许你可以用RepaintBoundary 截图然后裁剪PNG?

标签: flutter canvas flutter-layout flutter-dependencies flutter-animation


【解决方案1】:

好吧,我不知道 x 和 y,但你可以做的是带有包 screenshotlink 的特定小部件的屏幕截图

这个包将小部件捕获为图像,即使它们没有呈现在屏幕上。

第 1 步:创建控制器

ScreenshotController screenshotController = ScreenshotController();

第 2 步:使用 Screenshot() 包装小部件

Screenshot(
    controller: screenshotController,
    child: Text("This text will be captured as image"),
),

第三步:调用 capture 方法进行截图。这将返回一个 Uint8List

screenshotController.capture().then((Uint8List image) {
    //Capture Done
    setState(() {
        _imageFile = image;
    });
}).catchError((onError) {
    print(onError);
});

【讨论】:

    【解决方案2】:

    通过 RepaintBoundary 小部件,您可以截取您想要的特定区域的屏幕截图。我在这里举了一个我在我的项目中执行的例子。请随它去。希望对你有帮助。

    先声明全局键...

     GlobalKey globalKey = GlobalKey();
    

    然后使用这个 globalKey 用 RepaintBoundary 包装你的小部件,如下所示。

     RepaintBoundary(
                key: globalKey,
                child: Obx(() {
                  return Container(
                    decoration: BoxDecoration(image: DecorationImage(image: NetworkImage(mainController.imageName.value))),
                    height: 390,
                    width: 390,
                    child: Stack(
                      children: generatedNameWidgets,
                    ),
                  );
                })),
    

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      相关资源
      最近更新 更多