Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Camera Overlay

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?

like image 890
Pieter Avatar asked May 15 '18 10:05

Pieter


People also ask

How do you make a custom camera overlay?

Go to Menu > Overlays > Custom. Select Create, or select an existing overlay and select Clone or Edit. If creating a new overlay, enter a name for the overlay and select OK.

How do you customize your camera on flutter?

Create a new file called camera_screen. dart and define the CameraScreen stateful widget inside it. The controller will help you access the different functionalities of the camera, but before using them, you have to initialize the camera. Create a new method called onNewCameraSelected() .

How do I record videos from my camera on flutter?

To start recording the video, we will add a record button. It should overlay the video preview, so we will put the CameraPreview and the button into a Stack widget. Now, we need to create a new state variable _isRecording and set it to false. Line 2: We need to handle both, start and stop recording actions.


2 Answers

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,
        ),
      ),
    ),
  ],
);
like image 192
Antonino Avatar answered Sep 17 '22 12:09

Antonino


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.

like image 44
FlutterDevs Avatar answered Sep 20 '22 12:09

FlutterDevs