1# Interface (ColorManagement) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--SE: @leo_ysl--> 6<!--TSE: @xchaosioda--> 7 8> **NOTE** 9> 10> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 11> - The initial APIs of this interface are supported since API version 12. 12 13ColorManagement inherits from [ColorManagementQuery](arkts-apis-camera-ColorManagementQuery.md). 14 15It provides the APIs for color space settings. 16 17## Modules to Import 18 19```ts 20import { camera } from '@kit.CameraKit'; 21``` 22 23## setColorSpace<sup>12+</sup> 24 25setColorSpace(colorSpace: colorSpaceManager.ColorSpace): void 26 27Sets a color space. 28 29Before the setting, call [getSupportedColorSpaces](arkts-apis-camera-ColorManagementQuery.md#getsupportedcolorspaces12) to obtain the supported color spaces. You are advised to call this API after [addOutput](arkts-apis-camera-Session.md#addoutput11) and before [commitConfig](arkts-apis-camera-Session.md#commitconfig11-1). If this API is called after [commitConfig](arkts-apis-camera-Session.md#commitconfig11-1), the camera session configuration will take a longer time. 30 31**P3 and HDR Imaging** 32 33An application can deliver different color space parameters to declare its support for P3 and HDR. 34 35If an application does not proactively set the color space, SDR is used by default in photo capture scenarios. 36 37To obtain HDR images in photo capture scenarios, set the color space to P3. 38 39For different modes, enabling HDR, setting the color space, and configuring [CameraFormat](arkts-apis-camera-e.md#cameraformat) in the camera output stream [profile](arkts-apis-camera-i.md#profile) should match. For details, see the table below. For example, to enable HDR, set [CameraFormat](arkts-apis-camera-e.md#cameraformat) in the camera preview and video output stream [profiles](arkts-apis-camera-i.md#profile) to **CAMERA_FORMAT_YCRCB_P010** and the color space to **2020_HLG_LIMIT**. 40 41**Recording Mode** 42 43| SDR/HDR Photo Capture | CameraFormat | ColorSpace | 44|--------------------|--------------------------|------------------| 45| SDR | CAMERA_FORMAT_YUV_420_SP | BT709_LIMIT | 46| HDR_VIVID | CAMERA_FORMAT_YCRCB_P010/CAMERA_FORMAT_YCBCR_P010 | BT2020_HLG_LIMIT/BT2020_HLG_FULL | 47 48**Photo Mode** 49 50| SDR/HDR Photo Capture | ColorSpace | 51|--------------------|------------| 52| SDR(Default) | SRGB | 53| HDR | DISPLAY_P3 | 54 55**Atomic service API**: This API can be used in atomic services since API version 19. 56 57**System capability**: SystemCapability.Multimedia.Camera.Core 58 59**Parameters** 60 61| Name | Type | Mandatory| Description | 62| ------------ |---------------------- | -- | -------------------------- | 63| colorSpace | [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Yes| Color space, which is obtained by calling [getSupportedColorSpaces](arkts-apis-camera-ColorManagementQuery.md#getsupportedcolorspaces12). | 64 65**Error codes** 66 67For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 68 69| ID | Error Message | 70| --------------- | --------------- | 71| 7400101 | Parameter missing or parameter type incorrect. | 72| 7400102 | The colorSpace does not match the format. | 73| 7400103 | Session not config. | 74| 7400201 | Camera service fatal error. | 75 76**Example** 77 78```ts 79import { BusinessError } from '@kit.BasicServicesKit'; 80import { colorSpaceManager } from '@kit.ArkGraphics2D'; 81 82function setColorSpace(session: camera.PhotoSession, colorSpaces: Array<colorSpaceManager.ColorSpace>): void { 83 if (colorSpaces === undefined || colorSpaces.length <= 0) { 84 return; 85 } 86 try { 87 session.setColorSpace(colorSpaces[0]); 88 } catch (error) { 89 let err = error as BusinessError; 90 console.error(`The setColorSpace call failed, error code: ${err.code}`); 91 } 92} 93``` 94 95## getActiveColorSpace<sup>12+</sup> 96 97getActiveColorSpace(): colorSpaceManager.ColorSpace 98 99Obtains the color space in use. 100 101**Atomic service API**: This API can be used in atomic services since API version 19. 102 103**System capability**: SystemCapability.Multimedia.Camera.Core 104 105**Return value** 106 107| Type | Description | 108| ----------------------------------------------- | ---------------------------- | 109| [colorSpaceManager.ColorSpace](../apis-arkgraphics2d/js-apis-colorSpaceManager.md#colorspace) | Color space. | 110 111**Error codes** 112 113For details about the error codes, see [Camera Error Codes](errorcode-camera.md). 114 115| ID | Error Message | 116| --------------- | --------------- | 117| 7400103 | Session not config. | 118 119**Example** 120 121```ts 122import { BusinessError } from '@kit.BasicServicesKit'; 123import { colorSpaceManager } from '@kit.ArkGraphics2D'; 124 125function getActiveColorSpace(session: camera.PhotoSession): colorSpaceManager.ColorSpace | undefined { 126 let colorSpace: colorSpaceManager.ColorSpace | undefined = undefined; 127 try { 128 colorSpace = session.getActiveColorSpace(); 129 } catch (error) { 130 let err = error as BusinessError; 131 console.error(`The getActiveColorSpace call failed. error code: ${err.code}`); 132 } 133 return colorSpace; 134} 135``` 136