Harmony/OpenHarmony应用开发-矩阵变换

鸿蒙时代
发布于 2022-12-16 15:21
浏览
0收藏

可对图形进行平移、旋转和缩放等。
说明:从API Version 7开始支持。开发语言ets.

导入模块:import matrix4 from ‘@ohos.matrix4’

Harmony/OpenHarmony应用开发-矩阵变换-鸿蒙开发者社区

示例代码:

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()
    }
  }
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

示例效果:
Harmony/OpenHarmony应用开发-矩阵变换-鸿蒙开发者社区
代码地址: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

标签
HarmonyOpenHarmony应用开发-矩阵变换.docx 69.42K 17次下载
收藏
回复
举报
回复
    相关推荐