目录

@ohos.graphics.common2D (Common Data Types of 2D Graphics)

This module defines some common data types in the 2D graphics field, including color, rectangular area, and coordinate point, which are applicable to scenarios such as 2D graphics drawing. It provides developers with common graphics data structures to facilitate graphics computation and rendering operations.

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

  • This module uses the physical pixel unit, px.

Modules to Import

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

Color

Describes a color in ARGB format.

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

System capability: SystemCapability.Graphics.Drawing

Name Type Read-Only Optional Description
alpha number No No Alpha component of the color. The value is an integer ranging from 0 to 255.
red number No No Red component of the color. The value is an integer ranging from 0 to 255.
green number No No Green component of the color. The value is an integer ranging from 0 to 255.
blue number No No Blue component of the color. The value is an integer ranging from 0 to 255.

Rect

Defines a rectangular area by two coordinate points: the upper-left corner point and the lower-right corner point.

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

System capability: SystemCapability.Graphics.Drawing

Name Type Read-Only Optional Description
left number No No X-coordinate of the upper left corner of the rectangular area, a floating-point number. Unit: physical pixel px.
top number No No Y-coordinate of the upper left corner of the rectangular area, a floating-point number. Unit: physical pixel px.
right number No No X-coordinate of the lower right corner of the rectangular area, a floating-point number. Unit: physical pixel px.
bottom number No No Y-coordinate of the lower right corner of the rectangular area, a floating-point number. Unit: physical pixel px.

Point12+

Describes a coordinate point.

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

System capability: SystemCapability.Graphics.Drawing

Name Type Read-Only Optional Description
x number No No X-coordinate, a floating-point number. Unit: physical pixel px.
y number No No Y-coordinate, a floating-point number. Unit: physical pixel px.

Color4f20+

Describes a color in ARGB format, where each color component is a floating-point number ranging from 0.0 to 1.0.

System capability: SystemCapability.Graphics.Drawing

Name Type Read-Only Optional Description
alpha number No No Alpha component of the color. The value is a floating point number ranging from 0.0 to 1.0.
red number No No Red component of the color. The value is a floating point number ranging from 0.0 to 1.0.
green number No No Green component of the color. The value is a floating point number ranging from 0.0 to 1.0.
blue number No No Blue component of the color. The value is a floating point number ranging from 0.0 to 1.0.

Point3d12+

Describes a 3D coordinate point. It inherits from Point.

System capability: SystemCapability.Graphics.Drawing

Name Type Read-Only Optional Description
z number No No z-axis coordinate, a floating-point number. Unit: physical pixel px.