使用零快门延迟功能缩短延迟时间
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
从 CameraX 1.2 开始,零快门延迟可用作拍摄模式。与默认拍摄模式相比,启用零快门延迟后,延迟时间会明显缩短,这样您便不会错过拍摄机会。
启用零快门延迟
如需启用零快门延迟,请将 CAPTURE_MODE_ZERO_SHOT_LAG
传递给 ImageCapture.Builder.setCaptureMode()
。如果传递失败,setCaptureMode()
会回退到 CAPTURE_MODE_MINIMIZE_LATENCY
。
如需详细了解拍摄模式,请参阅图片拍摄指南。
运作方式
零快门延迟会使用环形缓冲区来存储三个最近拍摄的帧。当用户按下拍摄按钮时,CameraX 会调用 takePicture()
,环形缓冲区则会检索其时间戳最接近按钮按下时间的捕获帧。然后,CameraX 会重新处理拍摄会话,以从该帧生成以 JPEG 格式保存到磁盘的图片。
前提条件
在启用零快门延迟之前,请使用 isZslSupported()
确定相关设备是否符合以下要求:
如果设备不符合最低要求,CameraX 便会回退到 CAPTURE_MODE_MINIMIZE_LATENCY
。
零快门延迟仅适用于图片拍摄。您无法为视频拍摄或相机扩展程序启用该功能。
最后,由于使用闪光灯会增加延迟时间,因此当闪光灯开启或处于自动模式时,零快门延迟将不起作用。如需详细了解如何设置闪光灯模式,请参阅 setFlashMode()
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Reduce latency with Zero-Shutter Lag\n\n| **Note:** Zero-Shutter Lag is an experimental feature. To leave feedback on Zero-Shutter Lag, join the [Android CameraX Discussion Group](https://groups.google.com/a/android.com/g/camerax-developers).\n\nStarting in [CameraX 1.2](/jetpack/androidx/releases/camera), Zero-Shutter Lag is available as a capture mode.\nEnable Zero-Shutter Lag to significantly reduce latency compared to the\n[default capture mode](/reference/androidx/camera/core/ImageCapture#CAPTURE_MODE_MINIMIZE_LATENCY()), so you never miss the shot.\n\nEnable Zero-Shutter Lag\n-----------------------\n\nTo enable Zero-Shutter Lag, pass [`CAPTURE_MODE_ZERO_SHOT_LAG`](/reference/androidx/camera/core/ImageCapture#CAPTURE_MODE_ZERO_SHUTTER_LAG()) to\n[`ImageCapture.Builder.setCaptureMode()`](/reference/androidx/camera/core/ImageCapture.Builder#setCaptureMode(int)). If unsuccessful,\n`setCaptureMode()` falls back to `CAPTURE_MODE_MINIMIZE_LATENCY`.\n\nFor more on capture modes, see the [Image capture guide](/media/camera/camerax/take-photo#set-capture-mode).\n\nHow it works\n------------\n\nZero-Shutter Lag uses a ring buffer that stores the three most recent capture\nframes. When a user presses the capture button, CameraX invokes\n[`takePicture()`](/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)), and the ring buffer retrieves the captured frame with the\ntimestamp that is closest to that of the button press. CameraX then\n[reprocesses](/reference/android/hardware/camera2/CameraDevice#reprocessing) the capture session to generate an image from that frame, which\nsaves to disk in JPEG format.\n\nPrerequisites\n-------------\n\nBefore you enable Zero-Shutter Lag, use [`isZslSupported()`](/reference/androidx/camera/core/CameraInfo#isZslSupported()) to determine if\nyour device meets the following requirements:\n\n- Targets Android 6.0+ (API level 23 and higher).\n- Supports [`PRIVATE` reprocessing](/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING).\n\nFor devices that don't meet the minimum requirements, CameraX falls back to\n`CAPTURE_MODE_MINIMIZE_LATENCY`.\n\nZero-Shutter Lag is only available for [Image capture](/training/camerax/take-photo). You cannot enable it\nfor [Video capture](/training/camerax/video-capture) or with [Camera extensions](/training/camera/camera-extensions).\n\nFinally, because using flash results in greater latency, Zero-Shutter Lag does\nnot work when flash is ON or in AUTO mode. For more information about setting\nthe flash mode, see [`setFlashMode()`](/media/camera/camerax/take-photo#set-flash-mode)."]]