openharmony 鸿蒙 arkts-apis-graphics-drawing-e

2026-08-25 浏览 (1)

Enums

NOTE

  • 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.

  • The module operates under a single-threaded model. The caller needs to manage thread safety and context state transitions.

BlendMode

Enumerates the blend modes. A blend mode combines two colors (source color and destination color) in a specific way to create a new color. This is commonly used in graphics operations like overlaying, filtering, and masking. The blending process applies the same logic to the red, green, and blue color channels separately. The alpha channel, however, is handled according to the specific definitions of each blend mode.

For brevity, the following abbreviations are used:

s: source. d: destination. sa: source alpha. da: destination alpha.

The following abbreviations are used in the calculation result:

r: used when the calculation method is the same for the four channels (alpha, red, green, and blue channels). ra: used when only the alpha channel is manipulated. rc: used when the other three color channels are manipulated.

The table below shows the effect of each blend mode, where the yellow rectangle is the source and the blue circle is the destination.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
CLEAR0r = 0, sets the destination pixels to fully transparent.CLEAR
SRC1r = s (all channels of the result equal those of the source), replaces the destination pixels with the source pixels.SRC
DST2r = d (all channels of the result equal those of the destination), keeps the destination pixels unchanged.DST
SRC_OVER3r = s + (1 - sa) * d, draws the source pixels over the destination pixels, considering the source's transparency.SRC_OVER
DST_OVER4r = d + (1 - da) * s, draws the destination pixels over the source pixels, considering the destination's transparency.DST_OVER
SRC_IN5r = s * da, retains only the intersection of the source pixels with the opaque parts of the destination.SRC_IN
DST_IN6r = d * sa, retains only the intersection of the destination pixels with the opaque parts of the source.DST_IN
SRC_OUT7r = s * (1 - da), retains the parts of the source pixels that do not overlap with the destination.SRC_OUT
DST_OUT8r = d * (1 - sa), retains the parts of the destination pixels that do not overlap with the source.SRC_OUT
SRC_ATOP9r = s * da + d * (1 - sa), covers the destination pixels with the source pixels, showing the source only in the opaque parts of the destination.SRC_ATOP
DST_ATOP10r = d * sa + s * (1 - da), covers the source pixels with the destination pixels, showing the destination only in the opaque parts of the source.DST_ATOP
XOR11r = s * (1 - da) + d * (1 - sa), shows only the non-overlapping parts of the source and destination pixels.XOR
PLUS12r = min(s + d, 1), adds the color values of the source and destination pixels.PLUS
MODULATE13r = s * d, multiplies the color values of the source and destination pixels.MODULATE
SCREEN14r = s + d - s * d, inverts the color values of the source and destination pixels, multiplies them, and then inverts the result, typically producing a brighter outcome.SCREEN
OVERLAY15Selectively applies MULTIPLY or SCREEN based on the brightness of the destination pixels, enhancing contrast.OVERLAY
DARKEN16rc = s + d - max(s * da, d * sa), ra = s + (1 - sa) * d, takes the darker color values between the source and destination pixels.DARKEN
LIGHTEN17rc = s + d - min(s * da, d * sa), ra = s + (1 - sa) * d, takes the lighter color values between the source and destination pixels.LIGHTEN
COLOR_DODGE18Brightens the destination pixels by reducing contrast to reflect the source pixels.COLOR_DODGE
COLOR_BURN19Darkens the destination pixels by increasing contrast to reflect the source pixels.COLOR_BURN
HARD_LIGHT20Selectively applies MULTIPLY or SCREEN based on the brightness of the source pixels.HARD_LIGHT
SOFT_LIGHT21Softly brightens or darkens the destination pixels based on the brightness of the source pixels.SOFT_LIGHT
DIFFERENCE22rc = s + d - 2 * (min(s * da, d * sa)), ra = s + (1 - sa) * d, calculates the difference between the color values of the source and destination pixels.SOFT_LIGHT
EXCLUSION23rc = s + d - two(s * d), ra = s + (1 - sa) * d, similar to DIFFERENCE but with lower contrast.EXCLUSION
MULTIPLY24r = s * (1 - da) + d * (1 - sa) + s * d, multiplies the color values of the source and destination pixels, typically resulting in a darker outcome.MULTIPLY
HUE25Uses the hue of the source pixels and the saturation and brightness of the destination pixels.HUE
SATURATION26Uses the saturation of the source pixels and the hue and brightness of the destination pixels.SATURATION
COLOR27Uses the hue and saturation of the source pixels and the brightness of the destination pixels.COLOR
LUMINOSITY28Uses the brightness of the source pixels and the hue and saturation of the destination pixels.LUMINOSITY

PathMeasureMatrixFlags12+

Enumerates the dimensions of matrix information in path measurement. It is often used in animation scenarios where objects move along a path.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
GET_POSITION_MATRIX0Matrix corresponding to the position information.
GET_TANGENT_MATRIX1Matrix corresponding to the tangent information.
GET_POSITION_AND_TANGENT_MATRIX2Matrix corresponding to the position and tangent information.

SrcRectConstraint12+

Enumerates the constraints on the source rectangle. It is used to specify whether to limit the sampling range within the source rectangle when drawing an image on a canvas.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
STRICT0The sampling range is strictly confined to the source rectangle, resulting in a slow sampling speed.
FAST1The sampling range is not limited to the source rectangle and can extend beyond it, allowing for a high sampling speed.

ShadowFlag12+

Enumerates the shadow drawing behaviors.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
NONE0No shadow effect is used.
TRANSPARENT_OCCLUDER1The occluder is translucent.
GEOMETRIC_ONLY2Only the geometric shadow effect is used.
ALL3Shadow effects are combined, including the translucent occluder and geometric shadow.

PathOp12+

Enumerates the path operation types. It is often used in path combination and clipping scenarios.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
DIFFERENCE0Difference operation.
INTERSECT1Intersection operation.
UNION2Union operation.
XOR3XOR operation.
REVERSE_DIFFERENCE4Reverse difference operation.

PathIteratorVerb18+

Enumerates the path operation types contained in an iterator. It is used to read path operation instructions.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
MOVE0Sets the start point.
LINE1Adds a line segment.
QUAD2Adds a quadratic Bezier curve for smooth transitions.
CONIC3Adds a conic curve.
CUBIC4Adds a cubic Bezier curve for smooth transitions.
CLOSE5Closes a path.
DONECLOSE + 1The path setting is complete.

TextEncoding

Enumerates the text encoding types.

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

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
TEXT_ENCODING_UTF80One byte is used to indicate UTF-8 or ASCII characters.
TEXT_ENCODING_UTF161Two bytes are used to indicate most Unicode characters.
TEXT_ENCODING_UTF322Four bytes are used to indicate all Unicode characters.
TEXT_ENCODING_GLYPH_ID3Two bytes are used to indicate the glyph index.

ClipOp12+

Enumerates the canvas clipping modes.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
DIFFERENCE0Clips a specified area. That is, the difference set is obtained.DIFFERENCE
INTERSECT1Retains a specified area. That is, the intersection is obtained.INTERSECT

NOTE

The diagrams show the result of cropping a circle based on different enumerated values after a rectangle is cropped in INTERSECT mode. The green area is the final area obtained.

FilterMode12+

Enumerates the filter modes.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
FILTER_MODE_NEAREST0Nearest filter mode.
FILTER_MODE_LINEAR1Linear filter mode.

PathDirection12+

Enumerates the directions of a closed contour.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
CLOCKWISE0Adds a closed contour clockwise.
COUNTER_CLOCKWISE1Adds a closed contour counterclockwise.

PathFillType12+

Enumerates the fill types of a path.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
WINDING0Specifies that "inside" is computed by a non-zero sum of signed edge crossings. Specifically, draws a point and emits a ray in any direction. A count is used to record the number of intersection points of the ray and path, and the initial count is 0. When encountering a clockwise intersection point (the path passes from the left to the right of the ray), the count increases by 1. When encountering a counterclockwise intersection point (the path passes from the right to the left of the ray), the count decreases by 1. If the final count is not 0, the point is inside the path and needs to be colored. If the final count is 0, the point is not colored.
EVEN_ODD1Specifies that "inside" is computed by an odd number of edge crossings. Specifically, draws a point and emits a ray in any direction. If the number of intersection points of the ray and path is an odd number, the point is considered to be inside the path and needs to be colored. If the number is an even number, the point is not colored.
INVERSE_WINDING2Same as WINDING, but draws outside of the path, rather than inside.
INVERSE_EVEN_ODD3Same as EVEN_ODD, but draws outside of the path, rather than inside.

NOTE
WINDING&EVEN_ODD
As shown in the above figure, the path is a circle, the arrow indicates the path direction, p is any point "inside" the path, the blue line is the ray emitted from p, and the black arrow indicates the fill result using blue under the corresponding fill type. Under the WINDING fill rule, the number of intersection points of the ray and path is 2 (not 0), and therefore p is colored. Under the EVEN_ODD filling rule, the number of intersection points of the ray and path is 2 (an even number), and therefore p is not colored.

PointMode12+

Enumerates the modes for drawing multiple points in an array.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
POINTS0Draws each point separately.
LINES1Draws every two points as a line segment.
POLYGON2Draws an array of points as an open polygon.

FontEdging12+

Enumerates the font edging types.

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

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
ALIAS0No anti-aliasing processing is used.
ANTI_ALIAS1Uses anti-aliasing to smooth the jagged edges.
SUBPIXEL_ANTI_ALIAS2Uses sub-pixel anti-aliasing to provide a smoother effect for jagged edges.

FontHinting12+

Enumerates the font hinting types.

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

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
NONE0No font hinting is used.
SLIGHT1Slight font hinting is used to improve contrast.
NORMAL2Normal font hinting is used to improve contrast.
FULL3Full font hinting is used to improve contrast.

FontMetricsFlags12+

Enumerates the font measurement flags, which is used to specify whether a field in the FontMetrics struct is valid.

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

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
UNDERLINE_THICKNESS_VALID1 << 0The underlineThickness field is valid.
UNDERLINE_POSITION_VALID1 << 1The underlinePosition field is valid.
STRIKETHROUGH_THICKNESS_VALID1 << 2The strikethroughThickness field is valid.
STRIKETHROUGH_POSITION_VALID1 << 3The strikethroughPosition field is valid.
BOUNDS_INVALID1 << 4The boundary measurement values (such as top, bottom, xMin, and xMax) are invalid.

RectType12+

Enumerates the types of rectangles used to fill the lattices. Used only in Lattice.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
DEFAULT0Draws an image into the lattice.
TRANSPARENT1Sets the lattice to transparent.
FIXEDCOLOR2Draws the colors in the fColors array in Lattice into a lattice.

PathDashStyle18+

Enumerates the drawing styles for path effects.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
TRANSLATE0Translates only, not rotating with the path.
ROTATE1Rotates with the path.
MORPH2Rotates with the path and stretches or compresses at turns to enhance smoothness.

TileMode12+

Enumerates the tile modes of the shader effect.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
CLAMP0Replicates the edge color if the shader effect draws outside of its original boundary.
REPEAT1Repeats the shader effect in both horizontal and vertical directions.
MIRROR2Repeats the shader effect in both horizontal and vertical directions, alternating mirror images.
DECAL3Renders the shader effect only within the original boundary.

JoinStyle12+

Enumerates the join styles of a pen. The join style defines the shape of the joints of a polyline segment drawn by the pen.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
MITER_JOIN0Mitered corner. If the angle of a polyline is small, its miter length may be inappropriate. In this case, you need to use the miter limit to limit the miter length.MITER_JOIN
ROUND_JOIN1Round corner.ROUND_JOIN
BEVEL_JOIN2Beveled corner.BEVEL_JOIN

CapStyle12+

Enumerates the cap styles of a pen. The cap style defines the style of both ends of a line segment drawn by the pen.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
FLAT_CAP0There is no cap style. Both ends of the line segment are cut off square.FLAT_CAP
SQUARE_CAP1Square cap style. Both ends have a square, the height of which is half of the width of the line segment, with the same width.SQUARE_CAP
ROUND_CAP2Round cap style. Both ends have a semicircle centered, the diameter of which is the same as the width of the line segment.ROUND_CAP

BlurType12+

Enumerates the blur types of a mask filter.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
NORMAL0Both the outer edges and the inner solid parts are blurred.NORMAL
SOLID1The inner solid part remains unchanged, while only the outer edges are blurred.SOLID
OUTER2Only the outer edges are blurred, with the inner solid part being fully transparent.OUTER
INNER3Only the inner solid part is blurred, while the outer edges remain sharp.INNER

ScaleToFit12+

Enumerates the modes of scaling a source rectangle into a destination rectangle.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
FILL_SCALE_TO_FIT0Scales the source rectangle to completely fill the destination rectangle, potentially changing the aspect ratio of the source rectangle.
START_SCALE_TO_FIT1Scales the source rectangle, preserving its aspect ratio, to align it to the upper left corner of the destination rectangle.
CENTER_SCALE_TO_FIT2Scales the source rectangle, preserving its aspect ratio, to align it to the center of the destination rectangle.
END_SCALE_TO_FIT3Scales the source rectangle, preserving its aspect ratio, to align it to the lower right corner of the destination rectangle.

RegionOp12+

Enumerates the operations for combining two regions.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
DIFFERENCE0Difference operation.CLEAR
INTERSECT1Intersect operation.INTERSECT
UNION2Union operation.UNION
XOR3XOR operation.XOR
REVERSE_DIFFERENCE4Reverse difference operation.REVERSE_DIFFERENCE
REPLACE5Replace operation.REPLACE

NOTE

The schematic diagram shows the result obtained by combining a red region with a blue region at different operation mode. The green region is the region obtained.

CornerPos12+

Enumerates the corner positions of a rounded rectangle.

System capability: SystemCapability.Graphics.Drawing

NameValueDescription
TOP_LEFT_POS0Top left corner of the rounded rectangle.
TOP_RIGHT_POS1Top right corner of the rounded rectangle.
BOTTOM_RIGHT_POS2Bottom right corner of the rounded rectangle.
BOTTOM_LEFT_POS3Bottom left corner of the rounded rectangle.

VertexMode23+

Enumerates the connection modes for vertex drawing.

System capability: SystemCapability.Graphics.Drawing

NameValueDescriptionDiagram
TRIANGLES_VERTEXMODE0Every three vertices come from different triangles.TRIANGLES_VERTEXMODE
TRIANGLESSTRIP_VERTEXMODE1Consecutive triangles share one edge. It is efficient for continuous surfaces.TRIANGLESSTRIP_VERTEXMODE
TRIANGLESFAN_VERTEXMODE2All triangles share one vertex. It is suitable for circles and sectors.TRIANGLESFAN_VERTEXMODE

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drawing-gpu-context-h

openharmony 鸿蒙 capi-drawing-nativepixelmap-

openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange

openharmony 鸿蒙 capi-drawing-oh-drawing-brush

openharmony 鸿蒙 capi-drawing-oh-drawing-image-info

openharmony 鸿蒙 capi-drawing-text-linetypography-h

openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage

openharmony 鸿蒙 capi-drawing-typeface-h

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

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