Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make this kind of camera overlay in flutter?

Tags:

flutter

enter image description here

So, I want to make this kind of camera overlay in flutter to take selfies. where face are would be focus and other part will be display in transparancy. How an I make It possible in flutter.

like image 251
wolfsoft Developer Avatar asked Oct 29 '25 19:10

wolfsoft Developer


2 Answers

You can use the camera plugin which is already there and customise as you want. There are examples also here: Camera

For overlay: There is a widget called CameraPreview it basically shows the camera only. So, you need to put Stack widget and do the necessary design over the CameraPreview widget and add the functionalities.

like image 74
Aswanath C K Avatar answered Oct 31 '25 10:10

Aswanath C K


class OverlayPainter extends CustomPainter {
  final double screenWidth;
  final double screenHeight;

  OverlayPainter({required this.screenWidth, required this.screenHeight});

  @override
  void paint(Canvas canvas, Size size) {
    final radius = screenWidth * 0.35;
    final strokeWidth = 2.0;
    final circlePath = Path()
      ..addOval(Rect.fromCircle(
        center: Offset(screenWidth / 2, screenHeight / 2.5),
        radius: radius,
      ));

    final outerPath = Path()
      ..addRect(Rect.fromLTWH(0, 0, screenWidth, screenHeight));
    final overlayPath =
        Path.combine(PathOperation.difference, outerPath, circlePath);

    final paint = Paint()
      ..color = Colors.black.withOpacity(0.7)
      ..style = PaintingStyle.fill;

    final borderPaint = Paint()
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeWidth = strokeWidth;

    canvas.drawPath(overlayPath, paint);
    canvas.drawCircle(
      Offset(screenWidth / 2, screenHeight / 2.5),
      radius,
      borderPaint,
    );
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}

Take Reference here

like image 24
Vishwesh Soni Avatar answered Oct 31 '25 12:10

Vishwesh Soni