中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
可对图形进行平移、旋转和缩放等。 说明:从API Version 7开始支持。开发语言ets.
导入模块:import matrix4 from ‘@ohos.matrix4’
示例代码:
import matrix4 from '@ohos.matrix4'; // 创建一个四阶矩阵 let matrix1 = matrix4.init([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) let matrix2 = matrix4.identity() @Entry @Component struct MatrixTransformation { private matrix1 = matrix4.identity().translate({x:100}) private matrix2 = this.matrix1.copy().scale({x:2}) @Builder init(){ Column() { Image($r("app.media.icon")) .width("40%") .height(100) .transform(matrix1) } } @Builder identity(){ Column() { Image($r("app.media.icon")) .width("40%") .height(100) .transform(matrix1) Image($r("app.media.icon")) .width("40%") .height(100) .margin({ top: 150 }) .transform(matrix2) } } @Builder copy(){ Column() { Image($r("app.media.icon")) .width("40%") .height(100) .transform(this.matrix1) Image($r("app.media.icon")) .width("40%") .height(100) .margin({top:50}) .transform(this.matrix2) } } build() { Column(){ this.init() this.identity() this.copy() } } }
示例效果: 代码地址:https://e.gitee.com/jltfcloudcn/repos/jltfcloudcn/jump_to/tree/master/AnimationMuster
参考地址:https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-matrix-transformation-0000001430440725-V3
微信扫码分享