demo修改

This commit is contained in:
tsm 2024-04-30 11:10:30 +08:00
parent 29cdeca658
commit 91d29155c5
1 changed files with 47 additions and 0 deletions

View File

@ -22,6 +22,12 @@ struct Index {
@State w:number = 0 @State w:number = 0
@State BytesNumber1:number = 0 @State BytesNumber1:number = 0
@State BytesNumber2:number = 0 @State BytesNumber2:number = 0
@State ImageKnifeOption1: ImageKnifeOption = {
loadSrc: $r('app.media.icon'),
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed')
}
transformSquare1(mUrl:Resource) { transformSquare1(mUrl:Resource) {
let imageKnifeOption:RequestOption = new RequestOption(); let imageKnifeOption:RequestOption = new RequestOption();
imageKnifeOption.load(mUrl) imageKnifeOption.load(mUrl)
@ -66,26 +72,32 @@ struct Index {
Button('png') Button('png')
.onClick(() => { .onClick(() => {
this.transformSquare1(pngUrl); this.transformSquare1(pngUrl);
}); });
Button('svg') Button('svg')
.onClick(() => { .onClick(() => {
this.transformSquare1(svgUrl); this.transformSquare1(svgUrl);
}); });
Button('bmp') Button('bmp')
.onClick(() => { .onClick(() => {
this.transformSquare1(bmpUrl); this.transformSquare1(bmpUrl);
}); });
Button('jpp') Button('jpp')
.onClick(() => { .onClick(() => {
this.transformSquare1(jpgUrl); this.transformSquare1(jpgUrl);
}); });
Button('gif') Button('gif')
.onClick(() => { .onClick(() => {
this.transformSquare1(gifUrl); this.transformSquare1(gifUrl);
}); });
Button('webp') Button('webp')
.onClick(() => { .onClick(() => {
this.transformSquare1(webpUrl); this.transformSquare1(webpUrl);
}); });
}.margin({top:20,bottom:20}) }.margin({top:20,bottom:20})
Text("原图字节大小:"+this.BytesNumber1) Text("原图字节大小:"+this.BytesNumber1)
@ -97,32 +109,65 @@ struct Index {
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
} }
Text('component用法')
}.height(300).width('100%').backgroundColor(Color.Pink) }.height(300).width('100%').backgroundColor(Color.Pink)
Text('降采样图片') Text('降采样图片')
Flex(){ Flex(){
Button('png') Button('png')
.onClick(() => { .onClick(() => {
this.transformSquare2(pngUrl); this.transformSquare2(pngUrl);
this.ImageKnifeOption1 = {
loadSrc: pngUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
Button('svg') Button('svg')
.onClick(() => { .onClick(() => {
this.transformSquare2(svgUrl); this.transformSquare2(svgUrl);
this.ImageKnifeOption1 = {
loadSrc: svgUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
Button('bmp') Button('bmp')
.onClick(() => { .onClick(() => {
this.transformSquare2(bmpUrl); this.transformSquare2(bmpUrl);
this.ImageKnifeOption1 = {
loadSrc: bmpUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
Button('jpp') Button('jpp')
.onClick(() => { .onClick(() => {
this.transformSquare2(jpgUrl); this.transformSquare2(jpgUrl);
this.ImageKnifeOption1 = {
loadSrc: jpgUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
Button('gif') Button('gif')
.onClick(() => { .onClick(() => {
this.transformSquare2(gifUrl); this.transformSquare2(gifUrl);
this.ImageKnifeOption1 = {
loadSrc: gifUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
Button('webp') Button('webp')
.onClick(() => { .onClick(() => {
this.transformSquare2(webpUrl); this.transformSquare2(webpUrl);
this.ImageKnifeOption1 = {
loadSrc: webpUrl,
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
}
}); });
}.margin({top:20,bottom:20}) }.margin({top:20,bottom:20})
@ -136,6 +181,8 @@ struct Index {
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
} }
Text('component用法')
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption1 }).width(200).height(200)
}.height(300).width('100%').backgroundColor(Color.Pink) }.height(300).width('100%').backgroundColor(Color.Pink)
} }
} }