当前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%') } }
当前Image对于.9图的使用是给Image组件设置resizable属性,达到图片局部拉伸的效果,文档可参考:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5\#resizable11