gpt4 book ai didi

camera - CustomPaint Over Camera Preview

转载 作者:IT老高 更新时间:2023-10-28 12:40:27 27 4
gpt4 key购买 nike

我正在尝试在 Flutter 中的相机预览上显示 CustomPaint 元素。现在,CustomPaint 元素显示在相机预览下方。我正在使用 Flutter camera plugin显示相机预览。我的代码如下。

class _CameraPreviewState extends State<CameraPreview> {

[...]

Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;

return new YidKitTheme(
new Center(
child: _isReady
? new Container(
height: height / 2,
child: new CustomPaint(
painter: new GuidelinePainter(),
child: new AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: new CameraPreview(controller)
),
)
)
: new CircularProgressIndicator()
)
);
}
}

class GuidelinePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = new Paint()
..strokeWidth = 3.0
..color = Colors.red
..style = PaintingStyle.stroke;

var path = new Path()..lineTo(50.0, 50.0);
canvas.drawPath(path, paint);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}

最佳答案

改变

      child: new CustomPaint(
painter: new GuidelinePainter(),
child: new AspectRatio(

      child: new CustomPaint(
foregroundPainter: new GuidelinePainter(),
child: new AspectRatio(

painter 先绘制(即背景),然后绘制 child,然后 foregroundPainter 最后绘制在子元素之上

关于camera - CustomPaint Over Camera Preview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50473495/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com