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:

  1. 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.

  2. 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.

  3. Set Capture Settings: Use the AVCapturePhotoSettings to specify when you want a constant color image. Set the isConstantColorEnabled property to request a constant color image. This can be controlled via a UI toggle in your app.

  4. 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 the didFinishProcessingPhoto callback twice, allowing you to choose between the constant color photo and the fallback.

  5. 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.