HarmonyOS 如何支持.9图

开发中遇到不能引用.9图

HarmonyOS
2024-12-26 13:31:56
6137浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

Image组件当前已支持点九图,可以通过设置resizable达到图片拉伸的效果 。

官网文档对应链接:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5#resizableoptions11

参考demo如下:

@Entry
@Component
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.Contain
  @State w: number = 300
  @State h: number = 300

  build() {
    Column({ space: 10 }) {
      if (this.show) {
        Image($r('app.media.avatar'))// 具体的图片
          .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-26 16:44:20
相关问题
HarmonyOS ArkTS是否支持.9
703浏览 • 1回复 待解决
HarmonyOS 支持使用.9吗?
933浏览 • 1回复 待解决
请问有没有支持.9的方案?
1084浏览 • 1回复 待解决
HarmonyOS 是否支持类似的.9的配置?
1320浏览 • 1回复 待解决
HarmonyOS9功能
1014浏览 • 1回复 待解决
如何实现类似.9 的功能
2530浏览 • 1回复 待解决
HarmonyOS 是否有.9的实现效果
701浏览 • 1回复 待解决
HarmonyOS 是否有适配点9的方案
705浏览 • 1回复 待解决
HarmonyOS有没有适配点9的方案
2797浏览 • 1回复 待解决
基于ArkUI实现类似.9的拉伸能力
1494浏览 • 1回复 待解决
Image组件是否支持.9图片
1072浏览 • 1回复 待解决
HarmonyOS 项目支持gif动吗?
1226浏览 • 1回复 待解决
HarmonyOS PixelMap支持gif动
955浏览 • 1回复 待解决
API 9 是否不支持 npm 了?
3499浏览 • 1回复 待解决
OpenHarmony SDK 只支持8和9么?
6216浏览 • 1回复 待解决
现在是否支持Webp动
3132浏览 • 1回复 待解决
HarmonyOS 支持获取视频首帧吗?
760浏览 • 1回复 待解决
api9支持三方包吗?
3970浏览 • 1回复 待解决