HarmonyOS .9.png图片类型

我试了下貌似不支持.9.png,如果碰到了这种需要拉伸的场景图片,应该要怎么处理啊?

HarmonyOS
2024-12-24 15:28:20
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

当前Image对于.9图的使用是给Image组件设置resizable属性,达到图片局部拉伸的效果,文档可参考:

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

@Entry
@Component
export struct Image9SliceSample {
  @State left: number = 30;
  @State right: number = 2;
  @State top: number = 2;
  @State bottom: number = 2;
  @State fit: ImageFit = ImageFit.Cover;
  @State w: number = 100
  @State h: number = 200

  @Builder
  ImageBuilder() {
    Image($r('app.media.image1'))// .objectFit(this.fit)
      // .backgroundColor(Color.Pink)
      // .padding(5)
      .resizable({
        slice: {
          top: `${this.top}px`,
          left: `${this.left}px`,
          bottom: `${this.bottom}px`,
          right: `${this.right}px`,
        }
      })
      .width(`${this.w}px`)
      .height(`${this.h}px`)
  }
  build() {
    Column({ space: 20 }) {

      Text("123")
        .background(this.ImageBuilder)
        .width(`${this.w}px`)
        .height(`${this.h}px`);
      Blank().height(80)// Image($r('app.media.wph'))
        // .objectFit(this.fit)
        // .backgroundColor(Color.Pink)
        // .padding(5)
        // .resizable({
        // slice: {
        // top: `${this.top}px`,
        // left: `${this.left}px`,
        // bottom: `${this.bottom}px`,
        // right: `${this.right}px`,
        // }
        // })
        // .width(`${this.w}px`)
        .height(`${this.h}px`)
      Row() {
        Button("add top to " + this.top).fontSize(10)
          .onClick(() => {
            this.top += 1
          })
        Button("add bottom " + this.bottom).fontSize(10)
          .onClick(() => {
            this.bottom += 1
          })
        Button("add left " + this.left).fontSize(10)
          .onClick(() => {
            this.left += 1
          })
        Button("add right " + this.right).fontSize(10)
          .onClick(() => {
            this.right += 1
          })
      }


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

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

    }
    .backgroundColor(Color.Orange)
    .width('100%').height('100%')
  }
}
  • 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.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
分享
微博
QQ
微信
回复
2024-12-24 18:49:49
相关问题
怎么修改PNG图片的颜色?
1605浏览 • 1回复 待解决
HarmonyOS是否.9 图片
2156浏览 • 1回复 待解决
png图片使用Image组件加载出现锯齿
2534浏览 • 1回复 待解决
Image组件是否支持.9图片
1072浏览 • 1回复 待解决
如何保存一张PNG图片到相册中
2663浏览 • 1回复 待解决
API 9 ETS如何进行压缩图片
929浏览 • 1回复 待解决
是下载成png,当图片来引用吗?
2654浏览 • 1回复 待解决
HarmonyOS 有无YUV格式转换png的api
662浏览 • 1回复 待解决
HarmonyOS 如何支持.9
617浏览 • 1回复 待解决
HarmonyOS9图功能
1010浏览 • 1回复 待解决
HarmonyOS ArkTS是否支持.9
698浏览 • 1回复 待解决