【问题标题】:How to set 3:4 Aspect Ratio Flutter camera preview如何设置 3:4 纵横比 Flutter 相机预览
【发布时间】:2019-12-06 05:51:05
【问题描述】:

我正在开发 Flutter 应用程序。我需要相机功能并决定为此使用Camera Plugin。我将纵横比设置为 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),
          )
        ),
      )

【问题讨论】:

    标签: android ios flutter dart camera


    【解决方案1】:

    我这样解决了我的问题

    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),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  )
    

    【讨论】:

    • 非常好的解决方案。就我而言,我使用横向模式,然后将纵横比更改为 4/3 而不是 3/4。它工作正常。谢谢兄弟。
    【解决方案2】:
    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),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-06
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多