Flutter CameraController 需要 5 秒以上才能捕获图像

问题描述 投票:0回答:1

onPressed 我正在拍摄图像,但拍摄图像需要 5 秒以上

class TakePictureScreen extends StatefulWidget {
  const TakePictureScreen({
    super.key,
    required this.camera,
  });

  final CameraDescription camera;

  @override
  TakePictureScreenState createState() => TakePictureScreenState();
}

上面是主类

  late CameraController _controller;
  late Future<void> _initializeControllerFuture;


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

    _controller = CameraController(widget.camera, ResolutionPreset.low,
        enableAudio: false);
    // _initializeControllerFuture = _controller.initialize();
    _initializeControllerFuture = _controller.initialize().then((_) {
      if (mounted) {
        _controller.setFocusMode(FocusMode.auto);
      }
    });
  }

在 onPressed 中我正在拍照

  onPressed: () async {
                        
                        final image = await _controller.takePicture();
}

但是此图像捕获需要 5 秒以上才能捕获图像。

我尝试了另一个相机包和 image_picker 包,它重定向到手机相机,并且工作正常。但我想在应用程序中捕获图像而没有任何延迟。

flutter flutter-dependencies flutter-animation
1个回答
0
投票
dependencies:
  camera: ^0.10.0+1  # Example version, check for the latest

await cameraController.setFlashMode(FlashMode.off);
cameraController = CameraController(
  cameras[0], // Choose the camera
  ResolutionPreset.high,
  enableAudio: false,
);
await cameraController.initialize();
cameraController = CameraController(
  cameras[0],
  ResolutionPreset.medium,
);
try {
  final XFile image = await cameraController.takePicture();
  // Handle the captured image
} catch (e) {
  print(e);
}
© www.soinside.com 2019 - 2024. All rights reserved.