flutter 应用程序中的相机问题(> Android 不支持所选的 imageFormatGroup。默认为 yuv420)

Problems with camera in flutter app (The selected imageFormatGroup is not supported by > Android. Defaulting to yuv420)

我在应用程序中集成摄影功能时遇到问题。 我被问到是否允许访问相机,但在那之后除了这个错误之外没有任何反应:

W/Camera (26849): The selected imageFormatGroup is not supported by Android. Defaulting to yuv420

I/CameraManagerGlobal(26849): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client...

这是我的代码:

class FaultReporting extends StatefulWidget {
  @override
  _FaultReportingState createState()=> _FaultReportingState();
}

class _FaultReportingState extends State<FaultReporting>{
  bool isReady=false;
  List<CameraDescription> cameras;
  CameraController camController;

  @override
  void initState() {
    super.initState();
    setupCameras();
  }

  Future<void> setupCameras() async {
    try {
      cameras = await availableCameras();
      camController = new CameraController(cameras[0], ResolutionPreset.medium);
      await camController.initialize();
    } on CameraException catch (_) {
      setState(() {
        isReady = false;
      });
    }
    setState(() {
      isReady = true;
    });
  }

...

child: ElevatedButton(
                                onPressed: (){
                                  if(!isReady && !camController.value.isInitialized)
                                    {
                                      return Container();
                                    }
                                    return AspectRatio(
                                      aspectRatio: camController.value.aspectRatio,
                                      child: CameraPreview(camController),
                                    );
                                },
...

我在 flutter 上使用相机时遇到了完全相同的错误。该消息只是通知您 imageFormatGroup 参数必须是 ImageFormatGroup.yuv420。 所以试试这个:

camController = new CameraController(
    cameras[0],
    ResolutionPreset.medium,
    imageFormatGroup: ImageFormatGroup.yuv420,
);