HarmonyOS ArkTS是否支持.9图

ArkTS支持.9图吗,不支持怎么处理?

HarmonyOS
2024-12-25 13:37:35
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

Image组件当前已支持.9图,可以通过设置resizable达到图片拉伸的效果。文档链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5#resizableoptions11

示例参考如下:

@Entry
@Component
struct SetSlice {
  @State top: number = 0
  @State bottom: number = 0
  @State left: number = 0
  @State right: number = 0
  @State fit: ImageFit = ImageFit.Cover
  // bubble3 宽472px高200px
  @State w: number = px2vp(472)
  @State h: number = px2vp(200)

  build() {

    Column({ space: 10 }) {
      Stack() {
        Image($r('app.media.bubble3'))
          .width(this.w)
          .height(this.h)
          .borderRadius(4)
          .resizable({
            slice: {
              top: this.top,
              bottom: this.bottom,
              left: this.left,
              right: this.right
            }
          })
          .objectFit(this.fit)
        Divider().strokeWidth(1).color(Color.Red)
          .position({ top: this.top })
        Divider().strokeWidth(1).color(Color.Yellow)
          .position({ bottom: this.bottom })
        Divider().strokeWidth(1).color(Color.Blue).vertical(true)
          .position({ left: this.left })
        Divider().strokeWidth(1).color(Color.Green).vertical(true)
          .position({ right: this.right })
      }
      .width(this.w)
      .height(this.h)

      Stack() {
        Text()
          .width(this.w)
          .height(this.h)
          .borderRadius(4)
          .backgroundImage($r('app.media.bubble3'))
          .backgroundImageSize({ width: this.w, height: this.h })
          .backgroundImageResizable({
            slice: {
              top: this.top,
              bottom: this.bottom,
              left: this.left,
              right: this.right
            }
          })
        Divider().strokeWidth(1).color(Color.Red)
          .position({ top: this.top })
        Divider().strokeWidth(1).color(Color.Yellow)
          .position({ bottom: this.bottom })
        Divider().strokeWidth(1).color(Color.Blue).vertical(true)
          .position({ left: this.left })
        Divider().strokeWidth(1).color(Color.Green).vertical(true)
          .position({ right: this.right })
      }
      .width(this.w)
      .height(this.h)

      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' + this.w).fontSize(10)
          .onClick(() => {
            this.w += 2
          })
        Button('add h' + this.h).fontSize(10)
          .onClick(() => {
            this.h += 2
          })
      }

      Row() {
        Button('reduce w' + this.w).fontSize(10)
          .onClick(() => {
            this.w -= 2
          })
        Button('reduce h' + this.h).fontSize(10)
          .onClick(() => {
            this.h -= 2
          })
      }
    }
    .width('100%')
    .height('100%')
    .backgroundColor(Color.Pink)
    .padding({ top: 10 })
  }
}
分享
微博
QQ
微信
回复
2024-12-25 16:31:17
相关问题
HarmonyOS 如何支持.9
174浏览 • 1回复 待解决
HarmonyOS 是否支持类似的.9的配置?
626浏览 • 1回复 待解决
HarmonyOS 支持使用.9吗?
566浏览 • 1回复 待解决
HarmonyOS 是否有.9的实现效果
194浏览 • 1回复 待解决
请问有没有支持.9的方案?
445浏览 • 1回复 待解决
HarmonyOS 是否有适配点9的方案
71浏览 • 1回复 待解决
HarmonyOS9功能
310浏览 • 1回复 待解决
Image组件是否支持.9图片
477浏览 • 1回复 待解决
API 9 是否支持 npm 了?
2972浏览 • 1回复 待解决
现在是否支持Webp动
2488浏览 • 1回复 待解决
如何实现类似.9 的功能
1729浏览 • 1回复 待解决
HarmonyOS是否.9 图片
1721浏览 • 1回复 待解决
HarmonyOS ArkTS里面是否支持renderjs
189浏览 • 1回复 待解决
HarmonyOS ArkTS是否支持反射语法
299浏览 • 1回复 待解决
HarmonyOS有没有适配点9的方案
2166浏览 • 1回复 待解决
基于ArkUI实现类似.9的拉伸能力
748浏览 • 1回复 待解决
HarmonyOS ArkTS是否支持使用匿名类
746浏览 • 2回复 待解决
除了GIF,是否支持其他格式
2213浏览 • 1回复 待解决
求告知ArkTS是否支持断言
482浏览 • 1回复 待解决
HarmonyOS ArkTS是否支持自定义注解
200浏览 • 1回复 待解决
ArkTS是否支持require方式引入模块
2091浏览 • 1回复 待解决