HarmonyOS 如何支持.9图

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

HarmonyOS
2024-12-26 13:31:56
浏览
收藏 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
    })
  }
}
分享
微博
QQ
微信
回复
2024-12-26 16:44:20
相关问题
HarmonyOS ArkTS是否支持.9
244浏览 • 1回复 待解决
HarmonyOS 支持使用.9吗?
602浏览 • 1回复 待解决
请问有没有支持.9的方案?
565浏览 • 1回复 待解决
HarmonyOS 是否支持类似的.9的配置?
744浏览 • 1回复 待解决
HarmonyOS9功能
479浏览 • 1回复 待解决
如何实现类似.9 的功能
1851浏览 • 1回复 待解决
HarmonyOS 是否有适配点9的方案
94浏览 • 1回复 待解决
HarmonyOS 是否有.9的实现效果
294浏览 • 1回复 待解决
基于ArkUI实现类似.9的拉伸能力
851浏览 • 1回复 待解决
HarmonyOS有没有适配点9的方案
2238浏览 • 1回复 待解决
Image组件是否支持.9图片
554浏览 • 1回复 待解决
HarmonyOS PixelMap支持gif动
252浏览 • 1回复 待解决
HarmonyOS 项目支持gif动吗?
659浏览 • 1回复 待解决
OpenHarmony SDK 只支持8和9么?
5690浏览 • 1回复 待解决
API 9 是否不支持 npm 了?
3013浏览 • 1回复 待解决
现在是否支持Webp动
2596浏览 • 1回复 待解决
HarmonyOS 支持获取视频首帧吗?
363浏览 • 1回复 待解决
api9支持三方包吗?
3409浏览 • 1回复 待解决