How do I use constant color capture?
Generated on 1/23/2025
1 search
To use constant color capture in your app, follow these steps:
-
Check Device Support: Ensure that your device supports the constant color API by checking the
isConstantColorSupported
property of the AV capture photo output. Note that this property can change if you switch cameras or formats. Currently, the iPhone 14 family, iPhone 15 family, and 2024 iPad Pros are supported. -
Configure the Capture Pipeline: Set up the AV capture pipeline to handle constant color requests. Constant color is a photo-only mode and requires a built-in wide-angle or dual wide camera. The session preset should be set accordingly. Since constant color uses the flash, ensure the flash mode is set to auto or on.
-
Set Capture Settings: Use the
AVCapturePhotoSettings
to specify when you want a constant color image. Set theisConstantColorEnabled
property to request a constant color image. This can be controlled via a UI toggle in your app. -
Handle Fallbacks: If the capture conditions are not ideal (e.g., insufficient flash brightness), you can opt to use a fallback photo by enabling the
isConstantColorFallbackPhotoDeliveryEnabled
property. This will trigger thedidFinishProcessingPhoto
callback twice, allowing you to choose between the constant color photo and the fallback. -
Analyze Confidence: The API provides a confidence map and a summary confidence value to help determine which parts of the image have high accuracy colors. This can be useful for deciding whether to use the constant color image or the fallback.
For more detailed code examples and demos, you can refer to the Keep colors consistent across captures (09:30) session from WWDC 2024.

Capture HDR content with ScreenCaptureKit
Learn how to capture high dynamic colors using ScreenCaptureKit, and explore new features like HDR support, microphone capture, and straight-to-file recording.

Keep colors consistent across captures
Meet the Constant Color API and find out how it can help people use your app to determine precise colors. You’ll learn how to adopt the API, explore its scientific and marketing potential, and discover best practices for making the most of the technology.