openharmony 鸿蒙 capi-drawing-region-h

2026-08-25 浏览 (1)

drawing_region.h

Overview

This file declares the functions related to the region in the drawing module, including creating a region, setting the boundary, and destroying a region.

File to include: <native_drawing/drawing_region.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Related module: Drawing

Summary

Enumerated value

Nametypedef KeywordDescription
OH_Drawing_RegionOpModeOH_Drawing_RegionOpModeDefines an enum for the operation modes available for a region.

Functions

NameDescription
OH_Drawing_Region* OH_Drawing_RegionCreate(void)Creates an OH_Drawing_Region object for more accurate graphical control.
OH_Drawing_Region* OH_Drawing_RegionCopy(const OH_Drawing_Region* region)Creates a copy of a region object.
bool OH_Drawing_RegionContains(OH_Drawing_Region* region, int32_t x, int32_t y)Checks whether a region contains the specified point.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If region is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
bool OH_Drawing_RegionOp(OH_Drawing_Region* region, const OH_Drawing_Region* other, OH_Drawing_RegionOpMode op)Combines two regions based on the specified operation mode.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either region or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If op is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
bool OH_Drawing_RegionSetRect(OH_Drawing_Region* region, const OH_Drawing_Rect* rect)Sets the boundary for an OH_Drawing_Region object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either region or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
bool OH_Drawing_RegionSetPath(OH_Drawing_Region* region, const OH_Drawing_Path* path, const OH_Drawing_Region* clip)Sets a region to the area described by the path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If region, path, or clip is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_RegionDestroy(OH_Drawing_Region* region)Destroys an OH_Drawing_Region object and reclaims the memory occupied by the object.
OH_Drawing_ErrorCode OH_Drawing_RegionEmpty(OH_Drawing_Region* region)Sets the existing region to empty.
OH_Drawing_ErrorCode OH_Drawing_RegionGetBoundaryPath(const OH_Drawing_Region* region, OH_Drawing_Path* path)Sets the path as the boundary of the region. If the region is empty, the path is also empty.
OH_Drawing_ErrorCode OH_Drawing_RegionGetBounds(const OH_Drawing_Region* region, OH_Drawing_Rect* rect)Obtains the smallest bounding rectangle that contains the region.
OH_Drawing_ErrorCode OH_Drawing_RegionIsComplex(const OH_Drawing_Region* region, bool* isComplex)Checks whether the region contains two or more rectangles.
OH_Drawing_ErrorCode OH_Drawing_RegionIsEmpty(const OH_Drawing_Region* region, bool* isEmpty)Checks whether the region is empty.
OH_Drawing_ErrorCode OH_Drawing_RegionIsRect(const OH_Drawing_Region* region, bool* isRect)Checks whether the region the same as a rectangle.
OH_Drawing_ErrorCode OH_Drawing_RegionQuickContains(const OH_Drawing_Region* region, int32_t left, int32_t top, int32_t right, int32_t bottom, bool* isContained)Checks whether the region is the same as a single rectangle and contains the specified rectangle.
OH_Drawing_ErrorCode OH_Drawing_RegionQuickReject(const OH_Drawing_Region* region, int32_t left, int32_t top, int32_t right, int32_t bottom, bool* isReject)Checks whether the region is empty or does not intersect the specified rectangle.
OH_Drawing_ErrorCode OH_Drawing_RegionTranslate(OH_Drawing_Region* region, int32_t dx, int32_t dy)Translates the region by a specified distance on the X and Y axes. If the region is empty, no operation is performed.

Enum Description

OH_Drawing_RegionOpMode

enum OH_Drawing_RegionOpMode

Description

Enumerates the operation modes available for a region.

Since: 12

ValueDescription
REGION_OP_MODE_DIFFERENCEDifference operation.
REGION_OP_MODE_INTERSECTIntersection operation.
REGION_OP_MODE_UNIONUnion operation.
REGION_OP_MODE_XORXOR operation.
REGION_OP_MODE_REVERSE_DIFFERENCEReverse difference operation.
REGION_OP_MODE_REPLACEReplacement operation.

Function Description

OH_Drawing_RegionCreate()

OH_Drawing_Region* OH_Drawing_RegionCreate(void)

Description

Creates an OH_Drawing_Region object for more accurate graphical control.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Returns

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

OH_Drawing_RegionCopy()

OH_Drawing_Region* OH_Drawing_RegionCopy(const OH_Drawing_Region* region)

Description

Creates a copy of a region object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object to be copied.

Returns

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

OH_Drawing_RegionContains()

bool OH_Drawing_RegionContains(OH_Drawing_Region* region, int32_t x, int32_t y)

Description

Checks whether a region contains the specified point.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If region is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
int32_t xX coordinate of the point.
int32_t yY coordinate of the point.

Returns

TypeDescription
boolReturns true if the region contains the specified point; returns false otherwise.

OH_Drawing_RegionOp()

bool OH_Drawing_RegionOp(OH_Drawing_Region* region, const OH_Drawing_Region* other, OH_Drawing_RegionOpMode op)

Description

Combines two regions based on the specified operation mode.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either region or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If op 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_Region* regionPointer to an OH_Drawing_Region object, in which the resulting region is saved.
const OH_Drawing_Region* otherPointer to the OH_Drawing_Region object.
OH_Drawing_RegionOpMode opOperation mode of the region. For details about the available options, see OH_Drawing_RegionOpMode.

Returns

TypeDescription
boolReturns true if the resulting region is not empty; returns false otherwise.

OH_Drawing_RegionSetRect()

bool OH_Drawing_RegionSetRect(OH_Drawing_Region* region, const OH_Drawing_Rect* rect)

Description

Sets the boundary for an OH_Drawing_Region object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either region or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object.

Returns

TypeDescription
boolReturns true if the setting is successful; returns false otherwise.

OH_Drawing_RegionSetPath()

bool OH_Drawing_RegionSetPath(OH_Drawing_Region* region, const OH_Drawing_Path* path, const OH_Drawing_Region* clip)

Description

Sets a region to the area described by the path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If region, path, or clip is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
const OH_Drawing_Path* pathPointer to the OH_Drawing_Path object.
const OH_Drawing_Region* clipPointer to the OH_Drawing_Region object.

Returns

TypeDescription
boolReturns true if the resulting region is not empty; returns false otherwise.

OH_Drawing_RegionDestroy()

void OH_Drawing_RegionDestroy(OH_Drawing_Region* region)

Description

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

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.

OH_Drawing_RegionEmpty()

OH_Drawing_ErrorCode OH_Drawing_RegionEmpty(OH_Drawing_Region* region)

Description

Sets the existing region to empty.

Since: 22

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if the region parameter is empty.

OH_Drawing_RegionGetBoundaryPath()

OH_Drawing_ErrorCode OH_Drawing_RegionGetBoundaryPath(const OH_Drawing_Region* region, OH_Drawing_Path* path)

Description

Sets the path as the boundary of the region. If the region is empty, the path is also empty.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
OH_Drawing_Path* pathPointer to the OH_Drawing_Path object. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or path is a null pointer.

OH_Drawing_RegionGetBounds()

OH_Drawing_ErrorCode OH_Drawing_RegionGetBounds(const OH_Drawing_Region* region, OH_Drawing_Rect* rect)

Description

Obtains the smallest bounding rectangle that contains the region.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or rect is a null pointer.

OH_Drawing_RegionIsComplex()

OH_Drawing_ErrorCode OH_Drawing_RegionIsComplex(const OH_Drawing_Region* region, bool* isComplex)

Description

Checks whether the region contains two or more rectangles.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
bool* isComplexWhether this region contains multiple rectangles. It is used as an output parameter. true means yes; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or isComplex is a null pointer.

OH_Drawing_RegionIsEmpty()

OH_Drawing_ErrorCode OH_Drawing_RegionIsEmpty(const OH_Drawing_Region* region, bool* isEmpty)

Description

Checks whether the region is empty.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
bool* isEmptyWhether the region is empty. It is used as an output parameter. true means yes; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or isEmpty is a null pointer.

OH_Drawing_RegionIsRect()

OH_Drawing_ErrorCode OH_Drawing_RegionIsRect(const OH_Drawing_Region* region, bool* isRect)

Description

Checks whether the region the same as a rectangle.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
bool* isRectWhether the region the same as a rectangle. It is used as an output parameter. true means yes; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or isRect is a null pointer.

OH_Drawing_RegionQuickContains()

OH_Drawing_ErrorCode OH_Drawing_RegionQuickContains(const OH_Drawing_Region* region, int32_t left, int32_t top, int32_t right, int32_t bottom, bool* isContained)

Description

Checks whether the region is the same as a single rectangle and contains the specified rectangle.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
int32_t leftX coordinate of the upper left corner of the specified rectangle.
int32_t topY coordinate of the upper left corner of the specified rectangle.
int32_t rightX coordinate of the lower right corner of the specified rectangle.
int32_t bottomY coordinate of the lower right corner of the specified rectangle.
bool* isContainedWhether the region is the same as a single rectangle and contains the specified rectangle. It is used as an output parameter.
true if the current region is the same as a single rectangle and contains the specified rectangle; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or isContained is a null pointer.

OH_Drawing_RegionQuickReject()

OH_Drawing_ErrorCode OH_Drawing_RegionQuickReject(const OH_Drawing_Region* region, int32_t left, int32_t top, int32_t right, int32_t bottom, bool* isReject)

Description

Checks whether the region is empty or does not intersect the specified rectangle.

Since: 23

Parameters

NameDescription
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
int32_t leftX coordinate of the upper left corner of the specified rectangle.
int32_t topY coordinate of the upper left corner of the specified rectangle.
int32_t rightX coordinate of the lower right corner of the specified rectangle.
int32_t bottomY coordinate of the lower right corner of the specified rectangle.
bool* isRejectWhether the region is empty or whether the specified rectangle does not intersect with the region. It is used as an output parameter.
true means yes; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region or isReject is a null pointer.

OH_Drawing_RegionTranslate()

OH_Drawing_ErrorCode OH_Drawing_RegionTranslate(OH_Drawing_Region* region, int32_t dx, int32_t dy)

Description

Translates the region by a specified distance on the X and Y axes. If the region is empty, no operation is performed.

Since: 23

Parameters

NameDescription
OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
int32_t dxDistance to be translated on the X axis, in pixels.
int32_t dyDistance to be translated on the Y axis, in pixels.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if region is a null pointer.

你可能感兴趣的鸿蒙文章

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