
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With