You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何实现相机预览画面的正确旋转显示?

Flutter iOS倒竖屏相机预览旋转问题求助

环境与依赖

  • 使用的Flutter包版本:
camera: ^0.10.0+4
path_provider: ^2.0.11
path: ^1.8.2
  • Flutter环境详情:
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.6, on macOS 12.6 21G115 darwin-x64, locale en-JP)
    • Flutter version 3.3.6 on channel stable at /Users/xxxx/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6928314d50 (5 weeks ago), 2022-10-25 16:34:41 -0400
    • Engine revision 3ad69d7be3
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/xxxx/src/android-sdks
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • iPhone SE2 MS (mobile) • XXXXXXXX-XXXXXXXXXXXXXXXX • ios            • iOS 16.1.1 20B101
    • macOS (desktop)        • macos                     • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)           • chrome                    • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

当前实现代码

CameraController初始化代码

CameraController cc = CameraController(
    firstCamera,
    ResolutionPreset.max,
    imageFormatGroup:
        Platform.isIOS ? ImageFormatGroup.bgra8888 : ImageFormatGroup.jpeg,
);
await cc.initialize();

相机预览渲染代码

Center(child: CameraPreview(cc)),

问题详情

Android端横竖屏切换时,预览有动画但表现符合预期,也可通过设置消除动画;但iPhone处于倒竖屏(portraitDown)状态时,预览画面会以横屏形式显示,不符合预期。

之前尝试用原生设备方向相关插件解决该问题,但预览旋转存在明显延迟,效果不够理想。

求更简洁、流畅的方式实现iOS倒竖屏状态下相机预览画面的正确旋转显示(注:此问题不涉及拍摄后图片的旋转处理)。

预览异常示意图

内容的提问来源于stack exchange,提问作者Ganessa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 02:30:45