HarmonyOS 使用resizable做图片拉伸,如何实现想要的效果

HarmonyOS
2024-12-25 12:27:22
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

参考示例如下:

@Entry
@Component
export struct ImageExample2 {
  @State show: Boolean = true
  @State top: number = 0
  @State bottom: number = 0
  @State left: number = 0
  @State right: number = 0
  @State fit: ImageFit = ImageFit.Cover
  @State w: number = 300
  @State h: number = 300

  build() {
    Column({ space: 10 }) {
      if (this.show) {
        Image($r("app.media.cat"))// 直接加载网络地址,请填写一个具体的网络图片地址
          .width(this.w)
          .height(this.h)
          .borderRadius(4)
          .padding(10)
          .resizable({
            slice: {
              top: this.top,
              bottom: this.bottom,
              left: this.left,
              right: this.right
            }
          })
          .objectFit(this.fit)
          .backgroundColor(Color.Orange)
      }
      Row() {
        Button("add top to " + this.top).fontSize(10)
          .onClick(() => {
            this.top += 2
          })
        Button("add bottom " + this.bottom).fontSize(10)
          .onClick(() => {
            this.bottom += 2
          })
        Button("add left " + this.left).fontSize(10)
          .onClick(() => {
            this.left += 2
          })
        Button("add right " + this.right).fontSize(10)
          .onClick(() => {
            this.right += 2
          })
      }

      Row() {
        Button("reduce top to " + this.top).fontSize(10)
          .onClick(() => {
            this.top -= 2
          })
        Button("reduce bottom " + this.bottom).fontSize(10)
          .onClick(() => {
            this.bottom -= 2
          })
        Button("reduce left " + this.left).fontSize(10)
          .onClick(() => {
            this.left -= 2
          })
        Button("reduce right " + this.right).fontSize(10)
          .onClick(() => {
            this.right -= 2
          })
      }

      Row() {
        Button("add w").fontSize(10)
          .onClick(() => {
            this.w += 2
          })
        Button("add h").fontSize(10)
          .onClick(() => {
            this.h += 2
          })
      }

    }.width("100%").height("100%").backgroundColor(Color.Pink)
    .onClick(() => {
      this.show = !this.show
    })
  }
}
  • 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.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
分享
微博
QQ
微信
回复
2024-12-25 15:45:22
相关问题
HarmonyOS 图片怎么高斯模糊效果
898浏览 • 1回复 待解决
想要实现一个图片裁剪功能
1243浏览 • 1回复 待解决
HarmonyOS 图片按压效果实现
798浏览 • 2回复 待解决
图片模糊效果如何实现
1601浏览 • 1回复 待解决
如何实现图片大图预览效果
3464浏览 • 1回复 待解决
HarmonyOS 下拉图片放大效果如何实现
900浏览 • 1回复 待解决
HarmonyOS 对于图片或者背景图拉伸
819浏览 • 1回复 待解决
HarmonyOS 如何使一张图片拉伸但不变形
1390浏览 • 1回复 待解决
HarmonyOS image resizable问题咨询
1527浏览 • 1回复 待解决
HarmonyOS 想要实现图中这样UI
993浏览 • 1回复 待解决