openharmony 鸿蒙 js-apis-colorSpaceManager

2025-06-12 浏览 (1)

@ohos.graphics.colorSpaceManager (Color Space Management)

The colorSpaceManager module provides APIs for creating and managing color space objects and obtaining basic color space attributes.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { colorSpaceManager } from '@kit.ArkGraphics2D';

ColorSpace

Enumerates the color space types.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

NameValueDescription
UNKNOWN0Unknown type.
ADOBE_RGB_19981Adobe RGB (1998).
The conversion function is of the Adobe RGB (1998) type.
The encoding range is of the Full type.
DCI_P32DCI-P3.
The conversion function is of the Gamma 2.6 type.
The encoding range is of the Full type.
DISPLAY_P33Display P3.
The conversion function is of the SRGB type.
The encoding range is of the Full type.
SRGB4SRGB.
The conversion function is of the SRGB type.
The encoding range is of the Full type.
This is the default color space type.
CUSTOM5Custom type.
BT70911+6BT709.
The conversion function is of the BT709 type.
The encoding range is of the Full type.
BT601_EBU11+7BT601_P.
The conversion function is of the BT709 type.
The encoding range is of the Full type.
BT601_SMPTE_C11+8BT601_N.
The conversion function is of the BT709 type.
The encoding range is of the Full type.
BT2020_HLG11+9BT2020.
The conversion function is of the HLG type.
The encoding range is of the Full type.
BT2020_PQ11+10BT2020.
The conversion function is of the PQ type.
The encoding range is of the Full type.
P3_HLG11+11Display P3.
The conversion function is of the HLG type.
The encoding range is of the Full type.
P3_PQ11+12Display P3.
The conversion function is of the PQ type.
The encoding range is of the Full type.
ADOBE_RGB_1998_LIMIT11+13Adobe RGB (1998).
The conversion function is of the Adobe RGB (1998) type.
The encoding range is of the Limit type.
DISPLAY_P3_LIMIT11+14Display P3.
The conversion function is of the SRGB type.
The encoding range is of the Limit type.
SRGB_LIMIT11+15SRGB.
The conversion function is of the SRGB type.
The encoding range is of the Limit type.
BT709_LIMIT11+16BT709.
The conversion function is of the BT709 type.
The encoding range is of the Limit type.
BT601_EBU_LIMIT11+17BT601_P.
The conversion function is of the BT709 type.
The encoding range is of the Limit type.
BT601_SMPTE_C_LIMIT11+18BT601_N.
The conversion function is of the BT709 type.
The encoding range is of the Limit type.
BT2020_HLG_LIMIT11+19BT2020.
The conversion function is of the HLG type.
The encoding range is of the Limit type.
BT2020_PQ_LIMIT11+20BT2020.
The conversion function is of the PQ type.
The encoding range is of the Limit type.
P3_HLG_LIMIT11+21Display P3.
The conversion function is of the HLG type.
The encoding range is of the Limit type.
P3_PQ_LIMIT11+22Display P3.
The conversion function is of the PQ type.
The encoding range is of the Limit type.
LINEAR_P311+23Display P3.
The conversion function is of the Linear type.
LINEAR_SRGB11+24SRGB.
The conversion function is of the Linear type.
LINEAR_BT70911+24Same as that of LINEAR_SRGB.
BT709.
The conversion function is of the Linear type.
LINEAR_BT202011+25BT2020.
The conversion function is of the Linear type.
H_LOG18+26BT2020.
The conversion function is of the LOG type.
DISPLAY_SRGB11+4Same as that of SRGB.
SRGB.
The conversion function is of the SRGB type.
The encoding range is of the Full type.
DISPLAY_P3_SRGB11+3Same as that of DISPLAY_P3.
Display P3.
The conversion function is of the SRGB type.
The encoding range is of the Full type.
DISPLAY_P3_HLG11+11Same as that of P3_HLG.
Display P3.
The conversion function is of the HLG type.
The encoding range is of the Full type.
DISPLAY_P3_PQ11+12Same as that of P3_PQ.
Display P3.
The conversion function is of the PQ type.
The encoding range is of the Full type.

ColorSpacePrimaries

Defines the color space primaries. A color space is defined by chromaticity coordinates of the red, green, and blue additive primaries, the white point, and the gamma.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

NameTypeReadableWritableDescription
redXnumberYesYesX coordinate of the red color in the color space.
redYnumberYesYesY coordinate of the red color in the color space.
greenXnumberYesYesX coordinate of the green color in the color space.
greenYnumberYesYesY coordinate of the green color in the color space.
blueXnumberYesYesX coordinate of the blue color in the color space.
blueYnumberYesYesY coordinate of the blue color in the color space.
whitePointXnumberYesYesX coordinate of the white point in the color space.
whitePointYnumberYesYesY coordinate of the white point in the color space.

colorSpaceManager.create

create(colorSpaceName: ColorSpace): ColorSpaceManager

Creates a standard color space object.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

Parameters

ParameterTypeMandatoryDescription
colorSpaceNameColorSpaceYesType of the color space.
UNKNOWN and CUSTOM cannot be used when creating standard color space objects.

Return value

TypeDescription
ColorSpaceManagerColor space object created.

Error codes

For details about the error codes, see Universal Error Codes and colorSpaceManager Error Codes.

IDError Message
401Parameter error. Possible cause: 1.Incorrect parameter type. 2.Parameter verification failed.
18600001The parameter value is abnormal.

Example

let colorSpace: colorSpaceManager.ColorSpaceManager;
try {
    colorSpace = colorSpaceManager.create(colorSpaceManager.ColorSpace.SRGB);
} catch (err) {
    console.log(`Failed to create SRGB colorSpace. Cause: ` + JSON.stringify(err));
}

colorSpaceManager.create

create(primaries: ColorSpacePrimaries, gamma: number): ColorSpaceManager

Creates a custom color space object.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

Parameters

ParameterTypeMandatoryDescription
primariesColorSpacePrimariesYesPrimaries of the color space.
gammanumberYesGamma of the color space.

Return value

TypeDescription
ColorSpaceManagerColor space object created.
The color space type is CUSTOM of ColorSpace.

Error codes

For details about the error codes, see Universal Error Codes and colorSpaceManager Error Codes.

IDError Message
401Parameter error. Possible cause: 1.Incorrect parameter type. 2.Parameter verification failed.
18600001The parameter value is abnormal.

Example

let colorSpace: colorSpaceManager.ColorSpaceManager;
try {
    let primaries: colorSpaceManager.ColorSpacePrimaries = {
        redX: 0.1,
        redY: 0.1,
        greenX: 0.2,
        greenY: 0.2,
        blueX: 0.3,
        blueY: 0.3,
        whitePointX: 0.4,
        whitePointY: 0.4
    };
    let gamma = 2.2;
    colorSpace = colorSpaceManager.create(primaries, gamma);
} catch (err) {
    console.log(`Failed to create colorSpace with customized primaries and gamma. Cause: ` + JSON.stringify(err));
}

ColorSpaceManager

Implements management of color space objects.

Before calling any of the following APIs, you must use create() to create a color space manager.

getColorSpaceName

getColorSpaceName(): ColorSpace

Obtains the color space type.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

Return value

TypeDescription
ColorSpaceColor space type.

Error codes

For details about the error codes, see colorSpaceManager Error Codes.

IDError Message
18600001The parameter value is abnormal.

Example

try {
    let spaceName = colorSpace.getColorSpaceName();
} catch (err) {
    console.log(`Fail to get colorSpace's name. Cause: ` + JSON.stringify(err));
}

getWhitePoint

getWhitePoint(): Array<number>

Obtains the coordinates of the white point in the color space.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

Return value

TypeDescription
Array<number>Coordinates [x, y] of the white point.

Error codes

For details about the error codes, see colorSpaceManager Error Codes.

IDError Message
18600001The parameter value is abnormal.

Example

try {
    let point = colorSpace.getWhitePoint();
} catch (err) {
    console.log(`Failed to get white point. Cause: ` + JSON.stringify(err));
}

getGamma

getGamma(): number

Obtains the gamma of the color space.

System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core

Return value

TypeDescription
numberGamma of the color space.

Error codes

For details about the error codes, see colorSpaceManager Error Codes.

IDError Message
18600001The parameter value is abnormal.

Example

try {
    let gamma = colorSpace.getGamma();
} catch (err) {
    console.log(`Failed to get gamma. Cause: ` + JSON.stringify(err));
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkGraphics 2D

harmony 鸿蒙BufferHandle

harmony 鸿蒙ColorSpacePrimaries

harmony 鸿蒙DisplaySoloist_ExpectedRateRange

harmony 鸿蒙_drawing

harmony 鸿蒙NativeColorSpaceManager

harmony 鸿蒙NativeDisplaySoloist

harmony 鸿蒙NativeVsync

harmony 鸿蒙NativeWindow

harmony 鸿蒙OH_Drawing_BitmapFormat

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/JuIoFK