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

2026-08-25 浏览 (1)

Class (RoundRect)

圆角矩形对象。

说明:

  • 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

  • 本Class首批接口从API version 12开始支持。

  • 本模块使用屏幕物理像素单位px。

  • 本模块为单线程模型策略,需要调用方自行管理线程安全和上下文状态的切换。

导入模块

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

constructor20+

constructor(roundRect: RoundRect)

拷贝一个圆角矩形。

系统能力: SystemCapability.Graphics.Drawing

参数:

参数名类型必填说明
roundRectRoundRect用于拷贝的圆角矩形。

示例:

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

let rect: common2D.Rect = {left : 100, top : 100, right : 500, bottom : 300};
let roundRect = new drawing.RoundRect(rect, 50, 50);
let roundRect2 = new drawing.RoundRect(roundRect);

constructor12+

constructor(rect: common2D.Rect, xRadii: number, yRadii: number)

构造一个圆角矩形对象,当且仅当xRadii和yRadii均大于0时,圆角生效,否则只会构造一个矩形。

系统能力: SystemCapability.Graphics.Drawing

参数:

参数名类型必填说明
rectcommon2D.Rect需要创建的圆角矩形区域。
xRadiinumberX轴上的圆角半径,该参数为浮点数,小于等于0时无效。单位为物理像素px。
yRadiinumberY轴上的圆角半径,该参数为浮点数,小于等于0时无效。单位为物理像素px。

错误码:

以下错误码的详细介绍请参见通用错误码

错误码ID错误信息
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types.

示例:

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

let rect: common2D.Rect = {left : 100, top : 100, right : 500, bottom : 300};
let roundRect = new drawing.RoundRect(rect, 50, 50);

setCorner12+

setCorner(pos: CornerPos, x: number, y: number): void

设置圆角矩形中指定圆角位置的圆角半径。

系统能力: SystemCapability.Graphics.Drawing

参数:

参数名类型必填说明
posCornerPos圆角位置。
xnumberx轴方向的圆角半径,该参数为浮点数,小于等于0时无效。单位为物理像素px。
ynumbery轴方向的圆角半径,该参数为浮点数,小于等于0时无效。单位为物理像素px。

错误码:

以下错误码的详细介绍请参见通用错误码

错误码ID错误信息
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed.

示例:

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

let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
roundRect.setCorner(drawing.CornerPos.TOP_LEFT_POS, 150, 150);

getCorner12+

getCorner(pos: CornerPos): common2D.Point

获取圆角矩形中指定圆角位置的圆角半径。

系统能力: SystemCapability.Graphics.Drawing

参数:

参数名类型必填说明
posCornerPos圆角位置。

返回值:

类型说明
common2D.Point返回一个点,其横坐标表示圆角x轴方向上的半径,纵坐标表示y轴方向上的半径。

错误码:

以下错误码的详细介绍请参见通用错误码

错误码ID错误信息
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed.

示例:

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

let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
let cornerRadius = roundRect.getCorner(drawing.CornerPos.BOTTOM_LEFT_POS);
console.info("getCorner---"+cornerRadius.x)
console.info("getCorner---"+cornerRadius.y)

offset12+

offset(dx: number, dy: number): void

将圆角矩形分别沿x轴方向和y轴方向平移dx,dy。

系统能力: SystemCapability.Graphics.Drawing

参数:

参数名类型必填说明
dxnumber表示x轴方向上的偏移量。正数表示向x轴正方向平移,负数表示向x轴负方向平移,该参数为浮点数。单位为物理像素px。
dynumber表示y轴方向上的偏移量。正数表示向y轴正方向平移,负数表示向y轴负方向平移,该参数为浮点数。单位为物理像素px。

错误码:

以下错误码的详细介绍请参见通用错误码

错误码ID错误信息
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types.

示例:

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

let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
roundRect.offset(100, 100);

你可能感兴趣的鸿蒙文章

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