openharmony 鸿蒙 capi-drawing-pen-h

2026-08-25 浏览 (1)

drawing_pen.h

Overview

This file declares functions related to the pen in the drawing module.

Sample: NDKAPIDrawing (API Version 20)

File to include: <native_drawing/drawing_pen.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Related module: Drawing

Summary

Structs

Nametypedef KeywordDescription
OH_NativeColorSpaceManagerOH_NativeColorSpaceManagerDeclares a color space manager object to provide the capability of obtaining basic color space attributes.

Enums

Nametypedef KeywordDescription
OH_Drawing_PenLineCapStyleOH_Drawing_PenLineCapStyleDefines an enum for the line cap styles of a pen. The line cap style defines the style of both ends of a line segment drawn by the pen.
OH_Drawing_PenLineJoinStyleOH_Drawing_PenLineJoinStyleEnumerates the line join styles of a pen. The line join style defines the shape of the joints of a polyline segment drawn by the pen.

Functions

NameDescription
OH_Drawing_Pen* OH_Drawing_PenCreate(void)Creates an OH_Drawing_Pen object.
OH_Drawing_Pen* OH_Drawing_PenCopy(OH_Drawing_Pen* pen)Creates a copy of the OH_Drawing_Pen object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenDestroy(OH_Drawing_Pen* pen)Destroys an OH_Drawing_Pen object and reclaims the memory occupied by the object.
bool OH_Drawing_PenIsAntiAlias(const OH_Drawing_Pen* pen)Checks whether anti-aliasing is enabled for a pen. Anti-aliasing makes the pixels around the shape edges semi-transparent.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetAntiAlias(OH_Drawing_Pen* pen, bool antiAlias)Enables or disables anti-aliasing for a pen. Anti-aliasing makes the pixels around the shape edges semi-transparent.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
uint32_t OH_Drawing_PenGetColor(const OH_Drawing_Pen* pen)Obtains the color of a pen. The color is used by the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetColor(OH_Drawing_Pen* pen, uint32_t color)Sets the color for a pen. The color is used by the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
uint8_t OH_Drawing_PenGetAlpha(const OH_Drawing_Pen* pen)Obtains the alpha value of a pen. This value is used by the alpha channel when the pen outlines a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetAlpha(OH_Drawing_Pen* pen, uint8_t alpha)Sets the alpha value for a pen. This value is used by the alpha channel when the pen outlines a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
float OH_Drawing_PenGetWidth(const OH_Drawing_Pen* pen)Obtains the thickness of a pen. This thickness determines the width of the outline of a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetWidth(OH_Drawing_Pen* pen, float width)Sets the thickness for a pen. This thickness determines the width of the outline of a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
float OH_Drawing_PenGetMiterLimit(const OH_Drawing_Pen* pen)Obtains the stroke miter limit of a polyline drawn by a pen. When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, and a mitered corner is displayed if the miter limit is not exceeded.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetMiterLimit(OH_Drawing_Pen* pen, float miter)Sets the stroke miter limit for a polyline drawn by a pen. When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, and a mitered corner is displayed if the miter limit is not exceeded.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_PenLineCapStyle OH_Drawing_PenGetCap(const OH_Drawing_Pen* pen)Obtains the line cap style of a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetCap(OH_Drawing_Pen* pen, OH_Drawing_PenLineCapStyle capStyle)Sets the line cap style for a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If capStyle is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
OH_Drawing_PenLineJoinStyle OH_Drawing_PenGetJoin(const OH_Drawing_Pen* pen)Obtains the line join style of a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetJoin(OH_Drawing_Pen* pen, OH_Drawing_PenLineJoinStyle joinStyle)Sets the join style for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If joinStyle is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
void OH_Drawing_PenSetShaderEffect(OH_Drawing_Pen* pen, OH_Drawing_ShaderEffect* shaderEffect)Sets the shader effect for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetShadowLayer(OH_Drawing_Pen* pen, OH_Drawing_ShadowLayer* shadowLayer)Sets the shadow layer for a pen. The shadow layer effect takes effect only when text is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetPathEffect(OH_Drawing_Pen* pen, OH_Drawing_PathEffect* pathEffect)Sets the path effect for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetFilter(OH_Drawing_Pen* pen, OH_Drawing_Filter* filter)Sets a filter for a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenGetFilter(OH_Drawing_Pen* pen, OH_Drawing_Filter* filter)Obtains the OH_Drawing_Filter object from the pen. The filter is a container that holds a mask filter and color filter.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either pen or filter is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenSetBlendMode(OH_Drawing_Pen* pen, OH_Drawing_BlendMode blendMode)Sets a blender for a pen. The blender implements the specified blend mode.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If blendMode is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
bool OH_Drawing_PenGetFillPath(OH_Drawing_Pen* pen, const OH_Drawing_Path* src, OH_Drawing_Path* dst,const OH_Drawing_Rect* rect, const OH_Drawing_Matrix* matrix)Obtains the source path outline drawn using this pen and represents it using a destination path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If any of pen, src, and dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_PenReset(OH_Drawing_Pen* pen)Resets a pen to the initial state.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_PenSetColor4f(OH_Drawing_Pen* pen, float a, float r, float g, float b,OH_NativeColorSpaceManager* colorSpaceManager)Sets the color for a pen, which is used to outline a shape.
The color is in ARGB format represented by floating-point numbers. The color space is specified by OH_NativeColorSpaceManager.
If colorSpaceManager is a null pointer, the SRGB (standard red, green, and blue color space based on IEC 61966-2.1:1999) color space is used as the default value.
OH_Drawing_ErrorCode OH_Drawing_PenGetAlphaFloat(OH_Drawing_Pen* pen, float* a)Obtains the alpha value of the pen color.
OH_Drawing_ErrorCode OH_Drawing_PenGetRedFloat(OH_Drawing_Pen* pen, float* r)Obtains the red component of the pen color.
OH_Drawing_ErrorCode OH_Drawing_PenGetGreenFloat(OH_Drawing_Pen* pen, float* g)Obtains the green component of the pen color.
OH_Drawing_ErrorCode OH_Drawing_PenGetBlueFloat(OH_Drawing_Pen* pen, float* b)Obtains the blue component of the pen color.

Enum Description

OH_Drawing_PenLineCapStyle

enum OH_Drawing_PenLineCapStyle

Description

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

Since: 8

EnumDescription
LINE_FLAT_CAPThere is no cap style. Both ends of the line segment are cut off square.
LINE_SQUARE_CAPSquare cap style. Both ends have a square, the height of which is half of the width of the line segment, with the same width.
LINE_ROUND_CAPRound cap style. Both ends have a semicircle centered, the diameter of which is the same as the width of the line segment.

OH_Drawing_PenLineJoinStyle

enum OH_Drawing_PenLineJoinStyle

Description

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

Since: 8

EnumDescription
LINE_MITER_JOINMitered 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.
LINE_ROUND_JOINRound corner.
LINE_BEVEL_JOINBeveled corner.

Function Description

OH_Drawing_PenCreate()

OH_Drawing_Pen* OH_Drawing_PenCreate(void)

Description

Creates an OH_Drawing_Pen object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Returns

TypeDescription
OH_Drawing_Pen*Returns the pointer to the OH_Drawing_Pen object created.

OH_Drawing_PenCopy()

OH_Drawing_Pen* OH_Drawing_PenCopy(OH_Drawing_Pen* pen)

Description

Creates a copy of the OH_Drawing_Pen object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
OH_Drawing_Pen*Returns the pointer to the OH_Drawing_Pen object created. If NULL is returned, the creation fails. The possible failure cause is that no memory is available or pen is NULL.

OH_Drawing_PenDestroy()

void OH_Drawing_PenDestroy(OH_Drawing_Pen* pen)

Description

Destroys an OH_Drawing_Pen object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

OH_Drawing_PenIsAntiAlias()

bool OH_Drawing_PenIsAntiAlias(const OH_Drawing_Pen* pen)

Description

Checks whether anti-aliasing is enabled for a pen. Anti-aliasing makes the pixels around the shape edges semi-transparent.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
boolReturns true if anti-aliasing is enabled; returns false otherwise.

OH_Drawing_PenSetAntiAlias()

void OH_Drawing_PenSetAntiAlias(OH_Drawing_Pen* pen, bool antiAlias)

Description

Enables or disables anti-aliasing for a pen. Anti-aliasing makes the pixels around the shape edges semi-transparent.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
bool antiAliasWhether to enable anti-aliasing. The value true means to enable anti-aliasing, and false means the opposite.

OH_Drawing_PenGetColor()

uint32_t OH_Drawing_PenGetColor(const OH_Drawing_Pen* pen)

Description

Obtains the color of a pen. The color is used by the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
uint32_tReturns a 32-bit (ARGB) variable that describes the color.

OH_Drawing_PenSetColor()

void OH_Drawing_PenSetColor(OH_Drawing_Pen* pen, uint32_t color)

Description

Sets the color for a pen. The color is used by the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
uint32_t colorColor, which is a 32-bit (ARGB) variable.

OH_Drawing_PenGetAlpha()

uint8_t OH_Drawing_PenGetAlpha(const OH_Drawing_Pen* pen)

Description

Obtains the alpha value of a pen. This value is used by the alpha channel when the pen outlines a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
uint8_tReturns an 8-bit variable that describes the alpha value.

OH_Drawing_PenSetAlpha()

void OH_Drawing_PenSetAlpha(OH_Drawing_Pen* pen, uint8_t alpha)

Description

Sets the alpha value for a pen. This value is used by the alpha channel when the pen outlines a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
uint8_t alphaAlpha value, which is an 8-bit variable.

OH_Drawing_PenGetWidth()

float OH_Drawing_PenGetWidth(const OH_Drawing_Pen* pen)

Description

Obtains the thickness of a pen. This thickness determines the width of the outline of a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
floatReturns the thickness.

OH_Drawing_PenSetWidth()

void OH_Drawing_PenSetWidth(OH_Drawing_Pen* pen, float width)

Description

Sets the thickness for a pen. This thickness determines the width of the outline of a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float widthThickness, which is a variable.

OH_Drawing_PenGetMiterLimit()

float OH_Drawing_PenGetMiterLimit(const OH_Drawing_Pen* pen)

Description

Obtains the stroke miter limit of a polyline drawn by a pen. When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, and a mitered corner is displayed if the miter limit is not exceeded.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
floatReturns the miter limit.

OH_Drawing_PenSetMiterLimit()

void OH_Drawing_PenSetMiterLimit(OH_Drawing_Pen* pen, float miter)

Description

Sets the stroke miter limit for a polyline drawn by a pen. When the corner type is bevel, a beveled corner is displayed if the miter limit is exceeded, and a mitered corner is displayed if the miter limit is not exceeded.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float miterStroke miter limit, which is a variable.

OH_Drawing_PenGetCap()

OH_Drawing_PenLineCapStyle OH_Drawing_PenGetCap(const OH_Drawing_Pen* pen)

Description

Obtains the line cap style of a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
OH_Drawing_PenLineCapStyleReturns the line cap style.

OH_Drawing_PenSetCap()

void OH_Drawing_PenSetCap(OH_Drawing_Pen* pen, OH_Drawing_PenLineCapStyle capStyle)

Description

Sets the line cap style for a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If capStyle is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
OH_Drawing_PenLineCapStyle capStyleLine cap style, which is a variable.

OH_Drawing_PenGetJoin()

OH_Drawing_PenLineJoinStyle OH_Drawing_PenGetJoin(const OH_Drawing_Pen* pen)

Description

Obtains the line join style of a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

Returns

TypeDescription
OH_Drawing_PenLineJoinStyleReturns the line join style.

OH_Drawing_PenSetJoin()

void OH_Drawing_PenSetJoin(OH_Drawing_Pen* pen, OH_Drawing_PenLineJoinStyle joinStyle)

Description

Sets the join style for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If joinStyle is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
OH_Drawing_PenLineJoinStyle joinStyleJoin style.

OH_Drawing_PenSetShaderEffect()

void OH_Drawing_PenSetShaderEffect(OH_Drawing_Pen* pen, OH_Drawing_ShaderEffect* shaderEffect)

Description

Sets the shader effect for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_ShaderEffect* shaderEffectPointer to an OH_Drawing_ShaderEffect object. If NULL is passed in, the shader effect will be cleared.

OH_Drawing_PenSetShadowLayer()

void OH_Drawing_PenSetShadowLayer(OH_Drawing_Pen* pen, OH_Drawing_ShadowLayer* shadowLayer)

Description

Sets the shadow layer for a pen. The shadow layer effect takes effect only when text is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_ShadowLayer* shadowLayerPointer to an OH_Drawing_ShadowLayer object. If NULL is passed in, the shadow layer effect will be cleared.

OH_Drawing_PenSetPathEffect()

void OH_Drawing_PenSetPathEffect(OH_Drawing_Pen* pen, OH_Drawing_PathEffect* pathEffect)

Description

Sets the path effect for this pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_PathEffect* pathEffectPointer to an OH_Drawing_PathEffect object. If NULL is passed in, the path effect will be cleared.

OH_Drawing_PenSetFilter()

void OH_Drawing_PenSetFilter(OH_Drawing_Pen* pen, OH_Drawing_Filter* filter)

Description

Sets a filter for a pen.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_Filter* filterPointer to an OH_Drawing_Filter object. If NULL is passed in, the filter will be cleared.

OH_Drawing_PenGetFilter()

void OH_Drawing_PenGetFilter(OH_Drawing_Pen* pen, OH_Drawing_Filter* filter)

Description

Obtains the OH_Drawing_Filter object from the pen. The filter is a container that holds a mask filter and color filter.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either pen or filter is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_Filter* filterPointer to an OH_Drawing_Filter object.

OH_Drawing_PenSetBlendMode()

void OH_Drawing_PenSetBlendMode(OH_Drawing_Pen* pen, OH_Drawing_BlendMode blendMode)

Description

Sets a blender for a pen. The blender implements the specified blend mode.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If blendMode is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
OH_Drawing_BlendMode blendModeEnumeration of blend modes.

OH_Drawing_PenGetFillPath()

bool OH_Drawing_PenGetFillPath(OH_Drawing_Pen* pen, const OH_Drawing_Path* src, OH_Drawing_Path* dst,const OH_Drawing_Rect* rect, const OH_Drawing_Matrix* matrix)

Description

Obtains the source path outline drawn using this pen and represents it using a destination path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If any of pen, src, and dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.
const OH_Drawing_Path* srcPointer to the source OH_Drawing_Path object.
OH_Drawing_Path* dstPointer to the target OH_Drawing_Path object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object. NULL is recommended.
const OH_Drawing_Matrix* matrixPointer to an OH_Drawing_Matrix object. NULL is recommended. The default value is an identity matrix.

Returns

TypeDescription
boolReturns true if the destination path is obtained; returns false otherwise.

OH_Drawing_PenReset()

void OH_Drawing_PenReset(OH_Drawing_Pen* pen)

Description

Resets a pen to the initial state.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Pen* penPointer to the OH_Drawing_Pen object.

OH_Drawing_PenSetColor4f()

OH_Drawing_ErrorCode OH_Drawing_PenSetColor4f(OH_Drawing_Pen* pen, float a, float r, float g, float b,OH_NativeColorSpaceManager* colorSpaceManager)

Description

Sets the color for a pen, which is used to outline a shape.
The color is in ARGB format represented by floating-point numbers. The color space is specified by OH_NativeColorSpaceManager.
If colorSpaceManager is a null pointer, the SRGB (standard red, green, and blue color space based on IEC 61966-2.1:1999) color space is used as the default value.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float aAlpha value of the color, which is a floating-point number ranging from 0.0 to 1.0. Values above 1.0 default to 1.0, while values below 0.0 default to 0.0.
float rRed component of the color, which is a floating-point number ranging from 0.0 to 1.0. Values above 1.0 default to 1.0, while values below 0.0 default to 0.0.
float gGreen component of the color, which is a floating-point number ranging from 0.0 to 1.0. Values above 1.0 default to 1.0, while values below 0.0 default to 0.0.
float bBlue component of the color, which is a floating-point number ranging from 0.0 to 1.0. Values above 1.0 default to 1.0, while values below 0.0 default to 0.0.
OH_NativeColorSpaceManager* colorSpaceManagerPointer to an OH_NativeColorSpaceManager object.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if pen is NULL.

OH_Drawing_PenGetAlphaFloat()

OH_Drawing_ErrorCode OH_Drawing_PenGetAlphaFloat(OH_Drawing_Pen* pen, float* a)

Description

Obtains the alpha value of the pen color.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float* aAlpha value of the pen color. The value is a floating-point number ranging from 0.0 to 1.0.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if pen or a is NULL.

OH_Drawing_PenGetRedFloat()

OH_Drawing_ErrorCode OH_Drawing_PenGetRedFloat(OH_Drawing_Pen* pen, float* r)

Description

Obtains the red component of the pen color.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float* rRed component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if pen or r is NULL.

OH_Drawing_PenGetGreenFloat()

OH_Drawing_ErrorCode OH_Drawing_PenGetGreenFloat(OH_Drawing_Pen* pen, float* g)

Description

Obtains the green component of the pen color.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float* gGreen component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if pen or g is NULL.

OH_Drawing_PenGetBlueFloat()

OH_Drawing_ErrorCode OH_Drawing_PenGetBlueFloat(OH_Drawing_Pen* pen, float* b)

Description

Obtains the blue component of the pen color.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.
float* bBlue component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if pen or b is NULL.

你可能感兴趣的鸿蒙文章

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/v62f7llA