Starting in CameraX 1.2, Zero-Shutter Lag is available as a capture mode. Enable Zero-Shutter Lag to significantly reduce latency compared to the default capture mode, so you never miss the shot.
Enable Zero-Shutter Lag
To enable Zero-Shutter Lag, pass CAPTURE_MODE_ZERO_SHOT_LAG
to
ImageCapture.Builder.setCaptureMode()
. If unsuccessful,
setCaptureMode()
falls back to CAPTURE_MODE_MINIMIZE_LATENCY
.
For more on capture modes, see the Image capture guide.
How it works
Zero-Shutter Lag uses a ring buffer that stores the three most recent capture
frames. When a user presses the capture button, CameraX invokes
takePicture()
, and the ring buffer retrieves the captured frame with the
timestamp that is closest to that of the button press. CameraX then
reprocesses the capture session to generate an image from that frame, which
saves to disk in JPEG format.
Prerequisites
Before you enable Zero-Shutter Lag, use isZslSupported()
to determine if
your device meets the following requirements:
- Targets Android 6.0+ (API level 23 and higher).
- Supports
PRIVATE
reprocessing.
For devices that don't meet the minimum requirements, CameraX falls back to
CAPTURE_MODE_MINIMIZE_LATENCY
.
Zero-Shutter Lag is only available for Image capture. You cannot enable it for Video capture or with Camera extensions.
Finally, because using flash results in greater latency, Zero-Shutter Lag does
not work when flash is ON or in AUTO mode. For more information about setting
the flash mode, see setFlashMode()
.