首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >原生截图

原生截图
EN

Stack Overflow用户
提问于 2020-04-19 21:32:58
回答 1查看 135关注 0票数 0

在寻找了很长一段时间如何拍摄Webview截图后,我找到了这个包- native_screenshot

问题是,它在调试模式下工作,但不能在生产模式下工作-即使在使用pub.dev中发布的示例时也是如此。

我已经向android清单中添加了所需的权限,但仍然无法使其正常工作。

我已经向开发人员报告了这个问题,还在等待答复。我想知道这里是否有人能帮上忙。

我需要帮助才能让它起作用。感谢所有的帮助。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-03 09:07:29

webview_flutter插件没有提供截取WebView屏幕截图的方式或方法。因此,您可以尝试my plugin flutter_inappwebview,它是一个Flutter插件,允许您添加内联WebViews或打开应用程序中的浏览器窗口,它有许多事件、方法和选项来控制WebViews。

要截取屏幕,您可以使用InAppWebViewController.takeScreenshot方法,该方法获取WebView的可视视口的屏幕截图( PNG格式),并返回一个Uint8List

下面是一个示例,它在页面停止加载时截取WebView的屏幕截图,并显示一个带有相应屏幕截图的警告对话框:

代码语言:javascript
复制
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(initialRoute: '/', routes: {
      '/': (context) => InAppWebViewExampleScreen(),
    });
  }
}

class InAppWebViewExampleScreen extends StatefulWidget {
  @override
  _InAppWebViewExampleScreenState createState() =>
      new _InAppWebViewExampleScreenState();
}

class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
  InAppWebViewController webView;
  Uint8List screenshotBytes;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("InAppWebView")),
        body: Container(
            child: Column(children: <Widget>[
          Expanded(
              child: InAppWebView(
            initialUrl: "https://github.com/flutter",
            initialHeaders: {},
            initialOptions: InAppWebViewGroupOptions(
              crossPlatform: InAppWebViewOptions(
                  debuggingEnabled: true),
            ),
            onWebViewCreated: (InAppWebViewController controller) {
              webView = controller;
            },
            onLoadStart: (InAppWebViewController controller, String url) {},
            onLoadStop: (InAppWebViewController controller, String url) async {
              screenshotBytes = await controller.takeScreenshot();
              showDialog(
                context: context,
                builder: (context) {
                  return AlertDialog(
                    content: Image.memory(screenshotBytes),
                  );
                },
              );
            },
          ))
        ])));
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61305188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档