harmony 鸿蒙@ohos.graphics.colorSpaceManager (Color Space Management)

2022-11-09 浏览 (919)

@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 '@ohos.graphics.colorSpaceManager';

ColorSpace

Enumerates the color space types.

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

NameValueDescription
UNKNOWN0Unknown type.
ADOBE_RGB_19981Adobe RGB (1998).
DCI_P32DCI-P3.
DISPLAY_P33Display P3.
SRGB4SRGB.
This is the default color space type.
CUSTOM5Custom 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 colorSpaceManager Error Codes.

IDError Message
18600001Parameter 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 colorSpaceManager Error Codes.

IDError Message
18600001Parameter 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 object.

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
18600001Parameter value is abnormal.

Example

try {
    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 of 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
18600001Parameter value is abnormal.

Example

try {
    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
18600001Parameter value is abnormal.

Example

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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

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