簡體   English   中英

如何設置 3:4 縱橫比 Flutter 相機預覽

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM