drawing_brush.h
Overview
This file declares the functions related to the brush in the drawing module.
Sample: NDKAPIDrawing (API Version 20)
File to include: <native_drawing/drawing_brush.h>
Library: libnative_drawing.so
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Related module: Drawing
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_NativeColorSpaceManager | OH_NativeColorSpaceManager | Declares a color space manager object to provide the capability of obtaining basic color space attributes. |
Functions
| Name | Description |
|---|---|
| OH_Drawing_Brush* OH_Drawing_BrushCreate(void) | Creates an OH_Drawing_Brush object. |
| OH_Drawing_Brush* OH_Drawing_BrushCopy(OH_Drawing_Brush* brush) | Copies an existing OH_Drawing_Brush object to create a new one. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushDestroy(OH_Drawing_Brush* brush) | Destroys an OH_Drawing_Brush object and reclaims the memory occupied by the object. |
| bool OH_Drawing_BrushIsAntiAlias(const OH_Drawing_Brush* brush) | Checks whether anti-aliasing is enabled for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetAntiAlias(OH_Drawing_Brush* brush, bool antiAlias) | Enables or disables anti-aliasing for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| uint32_t OH_Drawing_BrushGetColor(const OH_Drawing_Brush* brush) | Obtains the color of a brush. The color is used by the brush to fill in a shape. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetColor(OH_Drawing_Brush* brush, uint32_t color) | Sets the color for a brush. The color is used by the brush to fill in a shape. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| uint8_t OH_Drawing_BrushGetAlpha(const OH_Drawing_Brush* brush) | Obtains the alpha value of a brush. This value is used by the alpha channel when the brush fills in a shape. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetAlpha(OH_Drawing_Brush* brush, uint8_t alpha) | Sets the alpha value for a brush. This value is used by the alpha channel when the brush fills in a shape. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetShaderEffect(OH_Drawing_Brush* brush, OH_Drawing_ShaderEffect* shaderEffect) | Sets the shader effect for a brush. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetShadowLayer(OH_Drawing_Brush* brush, OH_Drawing_ShadowLayer* shadowLayer) | Sets the shadow layer for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter) | Sets the filter OH_Drawing_Filter for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushGetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter) | Obtains the OH_Drawing_Filter object from the brush. 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 brush or filter is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BrushSetBlendMode(OH_Drawing_Brush* brush, OH_Drawing_BlendMode blendMode) | Sets a blender for a brush. The blender implements the specified blend mode. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush 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. |
| void OH_Drawing_BrushReset(OH_Drawing_Brush* brush) | Resets a brush to the initial state. All configured attributes are cleared. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| OH_Drawing_ErrorCode OH_Drawing_BrushSetColor4f(OH_Drawing_Brush* brush, float a, float r, float g, float b,OH_NativeColorSpaceManager* colorSpaceManager) | Sets a color for this brush. The color will be used by the brush to fill in 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_BrushGetAlphaFloat(const OH_Drawing_Brush* brush, float* a) | Obtains the alpha value of the brush color. |
| OH_Drawing_ErrorCode OH_Drawing_BrushGetRedFloat(const OH_Drawing_Brush* brush, float* r) | Obtains the red component of the brush color. |
| OH_Drawing_ErrorCode OH_Drawing_BrushGetGreenFloat(const OH_Drawing_Brush* brush, float* g) | Obtains the green component of the brush color. |
| OH_Drawing_ErrorCode OH_Drawing_BrushGetBlueFloat(const OH_Drawing_Brush* brush, float* b) | Obtains the blue component of the brush color. |
Function Description
OH_Drawing_BrushCreate()
OH_Drawing_Brush* OH_Drawing_BrushCreate(void)
Description
Creates an OH_Drawing_Brush object.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Returns
| Type | Description |
|---|---|
| OH_Drawing_Brush* | Returns the pointer to the OH_Drawing_Brush object created. |
OH_Drawing_BrushCopy()
OH_Drawing_Brush* OH_Drawing_BrushCopy(OH_Drawing_Brush* brush)
Description
Copies an existing OH_Drawing_Brush object to create a new one.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_Brush* | Returns a pointer to the OH_Drawing_Brush object created. If NULL is returned, the creation fails. The possible failure cause is that no memory is available or brush is NULL. |
OH_Drawing_BrushDestroy()
void OH_Drawing_BrushDestroy(OH_Drawing_Brush* brush)
Description
Destroys an OH_Drawing_Brush object and reclaims the memory occupied by the object.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
OH_Drawing_BrushIsAntiAlias()
bool OH_Drawing_BrushIsAntiAlias(const OH_Drawing_Brush* brush)
Description
Checks whether anti-aliasing is enabled for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
Returns
| Type | Description |
|---|---|
| bool | Returns true if anti-aliasing is enabled; returns false otherwise. |
OH_Drawing_BrushSetAntiAlias()
void OH_Drawing_BrushSetAntiAlias(OH_Drawing_Brush* brush, bool antiAlias)
Description
Enables or disables anti-aliasing for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| bool antiAlias | Whether to enable anti-aliasing. The value true means to enable anti-aliasing, and false means the opposite. |
OH_Drawing_BrushGetColor()
uint32_t OH_Drawing_BrushGetColor(const OH_Drawing_Brush* brush)
Description
Obtains the color of a brush. The color is used by the brush to fill in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
Returns
| Type | Description |
|---|---|
| uint32_t | Returns a 32-bit (ARGB) variable that describes the color. |
OH_Drawing_BrushSetColor()
void OH_Drawing_BrushSetColor(OH_Drawing_Brush* brush, uint32_t color)
Description
Sets the color for a brush. The color is used by the brush to fill in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| uint32_t color | Color, which is a 32-bit (ARGB) variable. |
OH_Drawing_BrushGetAlpha()
uint8_t OH_Drawing_BrushGetAlpha(const OH_Drawing_Brush* brush)
Description
Obtains the alpha value of a brush. This value is used by the alpha channel when the brush fills in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 11
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
Returns
| Type | Description |
|---|---|
| uint8_t | Returns an 8-bit variable that describes the alpha value. |
OH_Drawing_BrushSetAlpha()
void OH_Drawing_BrushSetAlpha(OH_Drawing_Brush* brush, uint8_t alpha)
Description
Sets the alpha value for a brush. This value is used by the alpha channel when the brush fills in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| uint8_t alpha | Alpha value, which is an 8-bit variable. |
OH_Drawing_BrushSetShaderEffect()
void OH_Drawing_BrushSetShaderEffect(OH_Drawing_Brush* brush, OH_Drawing_ShaderEffect* shaderEffect)
Description
Sets the shader effect for a brush.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| OH_Drawing_ShaderEffect* shaderEffect | Pointer to an OH_Drawing_ShaderEffect object. If NULL is passed in, the shader effect of the brush will be cleared. |
OH_Drawing_BrushSetShadowLayer()
void OH_Drawing_BrushSetShadowLayer(OH_Drawing_Brush* brush, OH_Drawing_ShadowLayer* shadowLayer)
Description
Sets the shadow layer for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| OH_Drawing_ShadowLayer* shadowLayer | Pointer to an OH_Drawing_ShadowLayer object. If NULL is passed in, the shadow layer effect of the brush will be cleared. |
OH_Drawing_BrushSetFilter()
void OH_Drawing_BrushSetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter)
Description
Sets the filter OH_Drawing_Filter for a brush. 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 brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 11
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| OH_Drawing_Filter* filter | Pointer to an OH_Drawing_Filter object. If null is passed in, the filter will be cleared. |
OH_Drawing_BrushGetFilter()
void OH_Drawing_BrushGetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter)
Description
Obtains the OH_Drawing_Filter object from the brush. 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 brush or filter is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to the OH_Drawing_Brush object. |
| OH_Drawing_Filter* filter | Pointer to an OH_Drawing_Filter object. |
OH_Drawing_BrushSetBlendMode()
void OH_Drawing_BrushSetBlendMode(OH_Drawing_Brush* brush, OH_Drawing_BlendMode blendMode)
Description
Sets a blender for a brush. The blender implements the specified blend mode.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush 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
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to the OH_Drawing_Brush object. |
| OH_Drawing_BlendMode blendMode | Enumeration of blend modes. |
OH_Drawing_BrushReset()
void OH_Drawing_BrushReset(OH_Drawing_Brush* brush)
Description
Resets a brush to the initial state. All configured attributes are cleared.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to the OH_Drawing_Brush object. |
OH_Drawing_BrushSetColor4f()
OH_Drawing_ErrorCode OH_Drawing_BrushSetColor4f(OH_Drawing_Brush* brush, float a, float r, float g, float b,OH_NativeColorSpaceManager* colorSpaceManager)
Description
Sets a color for this brush. The color will be used by the brush to fill in 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
| Name | Description |
|---|---|
| OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| float a | Alpha 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 r | Red 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 g | Green 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 b | Blue 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* colorSpaceManager | Pointer to an OH_NativeColorSpaceManager object. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ErrorCode | Execution result. OH_DRAWING_SUCCESS if the operation is successful. OH_DRAWING_ERROR_INVALID_PARAMETER if brush is NULL. |
OH_Drawing_BrushGetAlphaFloat()
OH_Drawing_ErrorCode OH_Drawing_BrushGetAlphaFloat(const OH_Drawing_Brush* brush, float* a)
Description
Obtains the alpha value of the brush color.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 20
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| float* a | Alpha value of the color. The value is a floating-point number ranging from 0.0 to 1.0. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ErrorCode | Execution result. OH_DRAWING_SUCCESS if the operation is successful. OH_DRAWING_ERROR_INVALID_PARAMETER if brush or a is NULL. |
OH_Drawing_BrushGetRedFloat()
OH_Drawing_ErrorCode OH_Drawing_BrushGetRedFloat(const OH_Drawing_Brush* brush, float* r)
Description
Obtains the red component of the brush color.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 20
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| float* r | Red component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ErrorCode | Execution result. OH_DRAWING_SUCCESS if the operation is successful. OH_DRAWING_ERROR_INVALID_PARAMETER if brush or r is NULL. |
OH_Drawing_BrushGetGreenFloat()
OH_Drawing_ErrorCode OH_Drawing_BrushGetGreenFloat(const OH_Drawing_Brush* brush, float* g)
Description
Obtains the green component of the brush color.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 20
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| float* g | Green component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ErrorCode | Execution result. OH_DRAWING_SUCCESS if the operation is successful. OH_DRAWING_ERROR_INVALID_PARAMETER if brush or g is NULL. |
OH_Drawing_BrushGetBlueFloat()
OH_Drawing_ErrorCode OH_Drawing_BrushGetBlueFloat(const OH_Drawing_Brush* brush, float* b)
Description
Obtains the blue component of the brush color.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 20
Parameters
| Name | Description |
|---|---|
| const OH_Drawing_Brush* brush | Pointer to an OH_Drawing_Brush object. |
| float* b | Blue component of the pen color. The value is a floating-point number ranging from 0.0 to 1.0. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ErrorCode | Execution result. OH_DRAWING_SUCCESS if the operation is successful. OH_DRAWING_ERROR_INVALID_PARAMETER if brush 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