Entry class for the global color picker function.
Since: 5.0.0(12)
Object of the color picker, including the basic information about the color picker.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.ColorPicker
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| color | common2D.Color | No | No | Color value. |
| colorSpace | colorSpaceManager.ColorSpace | No | No | Color space. |
| timestamp | number | No | No | Timestamp, which is the time elapsed since the system startup, in ms. |
| brightness | number | No | Yes | Color brightness, in nits. This parameter is returned when the pickHdrForResult API is called. The default value is 0. Since: 26.0.0 |
pickForResult(x?: number, y?: number): Promise<PickedColorInfo>
Global color picker, which does not support real-time display of RGB values. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.ColorPicker
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| x | number | No | X coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen width, in pixels. If the value exceeds the upper limit, the actual screen width is used. The default value is 100. |
| y | number | No | Y coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen height, in pixels. If the value exceeds the upper limit, the actual screen height is used. The default value is 100. |
Returns:
| Type | Description |
|---|---|
| Promise<PickedColorInfo> | Promise used to return the color pick-up execution result. Promise used to obtain the result of the global color pick-up operation. When the color pick-up is successful, an object containing the color information is returned. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 801 | api is not supported |
| 1013900001 | IPC communication failed |
| 1013900002 | memory is insufficient |
| 1013900003 | service is invalid |
| 1013900004 | multi app call |
| 1013900005 | background service call |
Example:
import { imageFeaturePicker } from '@kit.Penkit';
try {
// Parameter 0 indicates the X and Y coordinates of the initial position of the color picker. In the actual use scenario, the specific coordinates should be obtained based on user interaction.
imageFeaturePicker.pickForResult(0, 0).then(info => {
console.info(`info is ${JSON.stringify(info)}`);
})
} catch (error) {
console.error(`Failed to pickForResult. code: ${error.code}, message: ${error.message}`);
} pickForResult(x?: number, y?: number, showValue?: boolean): Promise<PickedColorInfo>
Global color picker, which supports real-time display of RGB values. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.ColorPicker
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| x | number | No | X coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen width, in pixels. If the value exceeds the upper limit, the actual screen width is used. The default value is 100. |
| y | number | No | Y coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen height, in pixels. If the value exceeds the upper limit, the actual screen height is used. The default value is 100. |
| showValue | boolean | No | Indicates whether to display the RGB value. The options are true (yes) and false (no). The default value is false. |
Returns:
| Type | Description |
|---|---|
| Promise<PickedColorInfo> | Promise used to return the color pick-up execution result. Promise used to obtain the result of the global color pick-up operation. When the color pick-up is successful, an object containing the color information is returned. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 801 | api is not supported |
| 1013900001 | IPC communication failed |
| 1013900002 | memory is insufficient |
| 1013900003 | service is invalid |
| 1013900004 | multi app call |
| 1013900005 | background service call |
Example:
import { imageFeaturePicker } from '@kit.Penkit';
try {
// Parameter 0 indicates the X and Y coordinates of the initial position of the color picker. In the actual use scenario, the specific coordinates should be obtained based on user interaction. The value true indicates that the RGB value is displayed.
imageFeaturePicker.pickForResult(0, 0, true).then(info => {
console.info(`info is ${JSON.stringify(info)}`);
})
} catch (error) {
console.error(`Failed to pickForResult. code: ${error.code}, message: ${error.message}`);
} pickHdrForResult(x?: number, y?: number): Promise<PickedColorInfo>
Global color picker (HDR images supported), which does not support real-time display of RGB values. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.ColorPicker
Since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| x | number | No | X coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen width, in pixels. If the value exceeds the upper limit, the actual screen width is used. The default value is 100. |
| y | number | No | Y coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen height, in pixels. If the value exceeds the upper limit, the actual screen height is used. The default value is 100. |
Returns:
| Type | Description |
|---|---|
| Promise<PickedColorInfo> | Promise used to return the color pick-up execution result. Promise used to obtain the result of the global color pick-up operation. When the color pick-up is successful, an object containing the color information is returned. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 801 | Capability not supported. The pickHdrForResult function cannot work properly due to limited device capabilities. |
| 1013900001 | IPC failed. |
| 1013900002 | Insufficient memory. |
| 1013900003 | Invalid service. |
| 1013900004 | Multi-app calling. |
| 1013900005 | Background service calling. |
Example:
import { imageFeaturePicker } from '@kit.Penkit';
try {
// Parameter 0 indicates the X and Y coordinates of the initial position of the color picker. In the actual use scenario, the specific coordinates should be obtained based on user interaction.
imageFeaturePicker.pickHdrForResult(0, 0).then(info => {
console.info(`info is ${JSON.stringify(info)}`);
})
} catch (error) {
console.error(`Failed to pickHdrForResult. code: ${error.code}, message: ${error.message}`);
} pickHdrForResult(x?: number, y?: number, showValue?: boolean): Promise<PickedColorInfo>
Global color picker (HDR images supported), which supports real-time display of RGB values. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.ColorPicker
Since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| x | number | No | X coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen width, in pixels. If the value exceeds the upper limit, the actual screen width is used. The default value is 100. |
| y | number | No | Y coordinate of the initial position of the color picker. The value ranges from 0 to the actual screen height, in pixels. If the value exceeds the upper limit, the actual screen height is used. The default value is 100. |
| showValue | boolean | No | Indicates whether to display the RGB value. The options are true (yes) and false (no). The default value is false. |
Returns:
| Type | Description |
|---|---|
| Promise<PickedColorInfo> | Promise used to return the color pick-up execution result. Promise used to obtain the result of the global color pick-up operation. When the color pick-up is successful, an object containing the color information is returned. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 801 | Capability not supported. The pickHdrForResult function cannot work properly due to limited device capabilities. |
| 1013900001 | IPC failed. |
| 1013900002 | Insufficient memory. |
| 1013900003 | Invalid service. |
| 1013900004 | Multi-app calling. |
| 1013900005 | Background service calling. |
Example:
import { imageFeaturePicker } from '@kit.Penkit';
try {
// Parameter 0 indicates the X and Y coordinates of the initial position of the color picker. In the actual use scenario, the specific coordinates should be obtained based on user interaction. The value true indicates that the RGB value is displayed.
imageFeaturePicker.pickHdrForResult(0, 0, true).then(info => {
console.info(`info is ${JSON.stringify(info)}`);
})
} catch (error) {
console.error(`Failed to pickHdrForResult. code: ${error.code}, message: ${error.message}`);
}