Compare commits
2 Commits
f3d8c91424
...
53d318817c
Author | SHA1 | Date |
---|---|---|
|
53d318817c | |
|
bb88cf558f |
|
@ -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 })
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue