Compare commits

..

2 Commits

Author SHA1 Message Date
Madi 53d318817c
Pre Merge pull request !433 from Madi/master 2024-11-25 09:04:50 +00:00
madixin bb88cf558f 1. ImageFit.Auto 组件宽度更改后自动支持自适应高度,并补充样例。
2.修复onLoadStart会调用2次的bug

Signed-off-by: madixin <madixin@huawei.com>
2024-11-25 17:03:41 +08:00
2 changed files with 15 additions and 13 deletions

View File

@ -15,42 +15,43 @@
import {
ImageKnifeComponent,
ImageKnifeData,
ImageKnifeRequest, LogUtil
ImageKnifeRequest
} from '@ohos/libraryimageknife';
@Entry
@Component
struct AutoImageFit {
@State width1: Length = '100%'
@State width1: Length = "100%"
build() {
Scroll() {
Column() {
Button($r('app.string.adjust_size')).onClick(() => {
if (this.width1.toString() == '100%') {
this.width1 = '60%'
if (this.width1.toString() == "100%") {
this.width1 = "60%"
} else {
this.width1 = '100%'
this.width1 = "100%"
}
}).width('100%')
Text('Image')
Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg').width('100%').objectFit(ImageFit.Auto)
Text('ImageKnife')
}).width("100%")
Text("Image")
Image("https://img1.baidu.com/it/u=313035107,662730619&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1233").width("100%").objectFit(ImageFit.Auto)
Text("ImageKnife")
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
loadSrc: "https://img1.baidu.com/it/u=313035107,662730619&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1233",
objectFit: ImageFit.Auto,
onLoadListener: {
onLoadStart: (request?: ImageKnifeRequest) => {
LogUtil.info('onLoadStart')
console.info("11111111111111111111 onLoadStart")
},
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
request?: ImageKnifeRequest) => {
LogUtil.info('onLoadSuccess')
console.info("11111111111111111111 onLoadSuccess")
}
}
}
}).width('100%')
}).width("100%")
}.width(this.width1).border({ width: 1 })
}

View File

@ -152,6 +152,7 @@ export struct ImageKnifeComponent {
this.pixelMap = pixelMap
if (typeof this.pixelMap !== 'string') {
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
// this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = this.currentWidth * size.height / size.width
this.isImageFitAutoResize = true
}