使用零延遲快門減少延遲時間
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
自 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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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)."]]