您可以使用getRectangleById获取组件大小、位置、平移缩放旋转及仿射矩阵属性信息参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-uicontext-V5\#getrectanglebyid示例demo:import matrix4 from '@ohos.matrix4'; import componentUtils from '@ohos.arkui.componentUtils'; @Entry @Component struct Utils { @State x: number = 120; @State y: number = 10; @State z: number = 100; @State value: string = ''; private matrix1 = matrix4.identity().translate({ x: this.x, y: this.y, z: this.z }); build() { Column() { Image($r("app.media.img")) .transform(this.matrix1) .translate({ x: 20, y: 20, z: 20 }) .scale({ x: 0.5, y: 0.5, z: 1 }) .rotate({ x: 1, y: 1, z: 1, centerX: '50%', centerY: '50%', angle: 300 }) .width(300) .height(100) .key("image_01") Button('getRectangleById') .onClick(() => { this.value = JSON.stringify(componentUtils.getRectangleById("image_01")) }).margin(10).id('onClick') Text(this.value) .margin(20) .width(300) .height(300) .borderWidth(2) }.margin({left: 50}) } }
您可以使用getRectangleById获取组件大小、位置、平移缩放旋转及仿射矩阵属性信息参考链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-uicontext-V5\#getrectanglebyid
示例demo: