Flutter Camera Overlay
Asked Answered
T

4

19

I've been doing some research for an upcoming project and would like to render the camera view behind a custom shape/semi-transparent img to act as a guide when taking pictures.

Does anyone know of a flutter camera plugin or tutorial that explains how to do this?

Thermy answered 15/5, 2018 at 10:28 Comment(0)
D
31

You can use the camera Plugin for flutter by the Flutter team.

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

and then position your image and you cameraview in a Stack Widget like this:

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,
        ),
      ),
    ),
  ],
);
Detroit answered 15/5, 2018 at 11:15 Comment(2)
Is there any way to save this video with the overlay?Enter
I want to save video with overlay as well? any suggestions..@JoseTapizquentAustriahungary
T
9

Please visit this repo. This example uses the camera plugin.

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.

Thinnish answered 2/11, 2018 at 7:55 Comment(0)
G
1

You can also now use this plugin : CamerAwesome

Official plugin has a ratio bug that makes overlay having bad ratio. This plugin includes flash, zoom, auto focus... and no initialisation required.

Gawen answered 24/11, 2020 at 8:6 Comment(0)
L
0

You can check full code on my page https://github.com/Prashantm111/flutter-camera-inscreen-app enter image description here

Luster answered 2/3, 2021 at 9:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.