Photo Output Callbacks
Understanding the Photo Output's callbacks and receiving Preview Images
The Photo Capture Pipeline (see "The Photo Output") has multiple stages for Photo capture.
Each stage invokes the respective callback - see CapturePhotoCallbacks.
Capture Events
A Photo capture has 3 stages:
To receive callbacks for each stage, pass CapturePhotoCallbacks to capturePhoto(...):
const photoOutput = ...
const photo = await photoOutput.capturePhoto(
{ /* options */},
{
onWillBeginCapture: () => console.log('will begin capture'),
onWillCapturePhoto: () => console.log('about to capture'),
onDidCapturePhoto: () => console.log('did capture'),
}
)Preview Image
A CameraPhotoOutput can be configured to deliver a preview-sized Image before the final Photo is ready, to display optimistic UIs or thumbnails.
First, specify your previewImageTargetSize:
const photoOutput = usePhotoOutput({
previewImageTargetSize: { width: 100, height: 150 }
})Then, in capturePhoto(...), pass a onPreviewImageAvailable() callback:
const photoOutput = ...
const photo = await photoOutput.capturePhoto(
{ /* options */},
{
onPreviewImageAvailable: (image) => {
console.log(`Received ${image.width}x${image.height} Image thumbnail!`)
}
}
)Preview Images are useful in long capture pipelines (e.g. 'quality' prioritization, or RAW capture) to provide a useful thumbnail upfront.