Flutter相机覆盖层

18

我正在为即将到来的项目做一些研究,想要在拍照时将自定义形状/半透明图片后面的相机视图呈现出来,以便作为指南。

有人知道任何一个Flutter相机插件或教程可以解释如何实现这个吗?

4个回答

30

您可以使用Flutter团队开发的摄像头插件。

https://pub.dartlang.org/packages/camera

然后将您的图像和相机视图放置在一个类似于以下方式的 Stack Widget 中:

return new Stack(
  alignment: FractionalOffset.center,
  children: <Widget>[
    new Positioned.fill(
      child: new AspectRatio(
          aspectRatio: controller.value.aspectRatio,
          child: new CameraPreview(controller)),
    ),
    new Positioned.fill(
      child: new Opacity(
        opacity: 0.3,
        child: new Image.network(
          'https://picsum.photos/3000/4000',
          fit: BoxFit.fill,
        ),
      ),
    ),
  ],
);

2
有没有办法将这个视频与叠加层一起保存? - tapizquent
我想保存带有叠加的视频,有什么建议吗?@JoseTapizquent - Rahul Kushwaha

9
请访问这个存储库。这个例子使用相机插件。
new AspectRatio(
  aspectRatio: controller.value.aspectRatio,
  child: Container(
    child: Stack(
      children: <Widget>[
        CameraPreview(controller),
        Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            width: double.infinity,
            height: 120.0,
            padding: EdgeInsets.all(20.0),
            color: Color.fromRGBO(00, 00, 00, 0.7),
            child: Stack(
              children: <Widget>[
                Align(
                  alignment: Alignment.center,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      borderRadius: BorderRadius.all(Radius.circular(50.0)),
                      onTap: () {
                        _captureImage();
                      },
                      child: Container(
                        padding: EdgeInsets.all(4.0),
                        child: Image.asset(
                          'assets/images/ic_shutter_1.png',
                          width: 72.0,
                          height: 72.0,
                        ),
                      ),
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.centerRight,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      borderRadius: BorderRadius.all(Radius.circular(50.0)),
                      onTap: () {
                        if (!_toggleCamera) {
                          onCameraSelected(widget.cameras[1]);
                          setState(() {
                            _toggleCamera = true;
                          });
                        } else {
                          onCameraSelected(widget.cameras[0]);
                          setState(() {
                            _toggleCamera = false;
                          });
                        }
                      },
                      child: Container(
                        padding: EdgeInsets.all(4.0),
                        child: Image.asset(
                          'assets/images/ic_switch_camera_3.png',
                          color: Colors.grey[200],
                          width: 42.0,
                          height: 42.0,
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  ),
);

enter image description here.


1
你现在也可以使用这个插件: CamerAwesome 官方插件存在一个比例错误,导致覆盖物比例不好。 该插件包含闪光灯、缩放、自动对焦等功能,无需初始化。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接