Compare commits
2 Commits
f3d8c91424
...
53d318817c
Author | SHA1 | Date |
---|---|---|
|
53d318817c | |
|
bb88cf558f |
|
@ -15,42 +15,43 @@
|
||||||
import {
|
import {
|
||||||
ImageKnifeComponent,
|
ImageKnifeComponent,
|
||||||
ImageKnifeData,
|
ImageKnifeData,
|
||||||
ImageKnifeRequest, LogUtil
|
ImageKnifeRequest
|
||||||
} from '@ohos/libraryimageknife';
|
} from '@ohos/libraryimageknife';
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct AutoImageFit {
|
struct AutoImageFit {
|
||||||
@State width1: Length = '100%'
|
@State width1: Length = "100%"
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Column() {
|
Column() {
|
||||||
Button($r('app.string.adjust_size')).onClick(() => {
|
Button($r('app.string.adjust_size')).onClick(() => {
|
||||||
if (this.width1.toString() == '100%') {
|
if (this.width1.toString() == "100%") {
|
||||||
this.width1 = '60%'
|
this.width1 = "60%"
|
||||||
} else {
|
} else {
|
||||||
this.width1 = '100%'
|
this.width1 = "100%"
|
||||||
}
|
}
|
||||||
}).width('100%')
|
}).width("100%")
|
||||||
Text('Image')
|
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)
|
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')
|
Text("ImageKnife")
|
||||||
ImageKnifeComponent({
|
ImageKnifeComponent({
|
||||||
imageKnifeOption: {
|
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,
|
objectFit: ImageFit.Auto,
|
||||||
onLoadListener: {
|
onLoadListener: {
|
||||||
onLoadStart: (request?: ImageKnifeRequest) => {
|
onLoadStart: (request?: ImageKnifeRequest) => {
|
||||||
LogUtil.info('onLoadStart')
|
console.info("11111111111111111111 onLoadStart")
|
||||||
},
|
},
|
||||||
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
|
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
|
||||||
request?: ImageKnifeRequest) => {
|
request?: ImageKnifeRequest) => {
|
||||||
LogUtil.info('onLoadSuccess')
|
console.info("11111111111111111111 onLoadSuccess")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).width('100%')
|
}).width("100%")
|
||||||
|
|
||||||
}.width(this.width1).border({ width: 1 })
|
}.width(this.width1).border({ width: 1 })
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,7 @@ export struct ImageKnifeComponent {
|
||||||
this.pixelMap = pixelMap
|
this.pixelMap = pixelMap
|
||||||
if (typeof this.pixelMap !== 'string') {
|
if (typeof this.pixelMap !== 'string') {
|
||||||
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
|
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
|
||||||
|
// this.adaptiveWidth = this.currentWidth
|
||||||
this.adaptiveHeight = this.currentWidth * size.height / size.width
|
this.adaptiveHeight = this.currentWidth * size.height / size.width
|
||||||
this.isImageFitAutoResize = true
|
this.isImageFitAutoResize = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue