[英]How to set 3:4 Aspect Ratio Flutter camera preview
我正在开发 Flutter 应用程序。 我需要相机功能并决定为此使用相机插件。 我将纵横比设置为 3:4,但图像扭曲且小于应有的尺寸。 我认为规模有问题。 设置相机纵横比(即 3:4)的正确方法是什么?
final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
final aspectRatio=3/4;
Transform.scale(
scale: controller.value.aspectRatio / deviceRatio,
child: Center(
child: AspectRatio(
aspectRatio: aspectRatio,
child: CameraPreview(controller),
)
),
)
我这样解决了我的问题
final size = MediaQuery.of(context).size.width;
Transform.scale(
scale: 1.0,
child: AspectRatio(
aspectRatio: 3.0 / 4.0,
child: OverflowBox(
alignment: Alignment.center,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Container(
width: size,
height: size / controller.value.aspectRatio,
child: Stack(
children: <Widget>[
CameraPreview(controller),
],
),
),
),
),
),
)
RotatedBox(
quarterTurns:
MediaQuery.of(context).orientation == Orientation.landscape
? 3
: 0,
child: Transform.scale(
scale: 1.0,
child: AspectRatio(
aspectRatio: 3.0 / 4.0,
child: OverflowBox(
alignment: Alignment.center,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Container(
width: size,
height: size / cameraController.value.aspectRatio,
child: Stack(
children: <Widget>[
CameraPreview(cameraController),
],
),
),
),
),
),
),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.