Pre Merge pull request !303 from xiagengwen/master

This commit is contained in:
xiagengwen 2024-06-11 11:12:33 +00:00 committed by Gitee
commit 9cdecb355d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 130 additions and 60 deletions

View File

@ -48,14 +48,46 @@ struct Index {
placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed') errorholderSrc: $r('app.media.icon_failed')
} }
private timeId:number = -1;
transformSquare1(mUrl: string|Resource|PixelMap) { transformSquare1(mUrl: string|Resource|PixelMap) {
let imageKnifeOption: RequestOption = new RequestOption(); let imageKnifeOption: RequestOption = new RequestOption();
imageKnifeOption.load(mUrl) imageKnifeOption.load(mUrl)
.addListener({ .addListener({
callback: (err: BusinessError | string, data: ImageKnifeData) => { callback: (err: BusinessError | string, data: ImageKnifeData) => {
if (this.timeId !== -1) {
clearTimeout(this.timeId);
}
this.originalMSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap; this.originalMSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
this.originalBytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber() if (!!this.originalMSquarePixelMap) {
this.originalBytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber();
} else {
let index: number = 0;
if (data.drawGIFFrame) {
if (data.drawGIFFrame.imageGIFFrames) {
let renderGif = () => {
if (data.drawGIFFrame) {
if (data.drawGIFFrame.imageGIFFrames) {
let pixelmap = data.drawGIFFrame.imageGIFFrames[index].drawPixelMap;
let delay = data.drawGIFFrame.imageGIFFrames[index].delay;
if (pixelmap) {
this.originalMSquarePixelMap = pixelmap;
this.originalBytesNumber = pixelmap.getPixelBytesNumber();
}
index++;
if (index == data.drawGIFFrame.imageGIFFrames.length - 1) {
index = 0;
}
if(!!delay) {
this.timeId = setTimeout(renderGif, data!.drawGIFFrame!.imageGIFFrames![index].delay);
}
}
}
}
renderGif();
}
}
}
return false; return false;
} }
}) })
@ -68,8 +100,39 @@ struct Index {
imageKnifeOption.load(mUrl) imageKnifeOption.load(mUrl)
.addListener({ .addListener({
callback: (err: BusinessError | string, data: ImageKnifeData) => { callback: (err: BusinessError | string, data: ImageKnifeData) => {
if (this.timeId !== -1) {
clearTimeout(this.timeId);
}
this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap; this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
this.bytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber() if (!!this.mSquarePixelMap) {
this.bytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber();
} else {
let index: number = 0;
if (data.drawGIFFrame) {
if (data.drawGIFFrame.imageGIFFrames) {
let renderGif = () => {
if (data.drawGIFFrame) {
if (data.drawGIFFrame.imageGIFFrames) {
let pixelmap = data.drawGIFFrame.imageGIFFrames[index].drawPixelMap;
let delay = data.drawGIFFrame.imageGIFFrames[index].delay;
if (pixelmap) {
this.mSquarePixelMap = pixelmap;
this.bytesNumber = pixelmap.getPixelBytesNumber();
}
index++;
if (index == data.drawGIFFrame.imageGIFFrames.length - 1) {
index = 0;
}
if(!!delay) {
this.timeId = setTimeout(renderGif, data!.drawGIFFrame!.imageGIFFrames![index].delay);
}
}
}
}
renderGif();
}
}
}
return false; return false;
} }
}) })
@ -131,16 +194,16 @@ struct Index {
this.transformSquare1(this.url); this.transformSquare1(this.url);
}); });
// Button('gif') Button('gif')
// .onClick(() => { .onClick(() => {
// this.transformSquare1(this.url); this.transformSquare1(this.url);
//
// }); });
// Button('webp') Button('webp')
// .onClick(() => { .onClick(() => {
// this.transformSquare1(this.url); this.transformSquare1(this.url);
//
// }); });
}.margin({ top: 20, bottom: 20 }) }.margin({ top: 20, bottom: 20 })
Text("原图字节大小:" + this.originalBytesNumber) Text("原图字节大小:" + this.originalBytesNumber)
@ -199,26 +262,26 @@ struct Index {
downsampling: new fitter() downsampling: new fitter()
} }
}); });
// Button('gif') Button('gif')
// .onClick(() => { .onClick(() => {
// // this.transformSquare2(this.url); // this.transformSquare2(this.url);
// this.imageKnifeOption = { this.imageKnifeOption = {
// loadSrc: gifUrl, loadSrc: gifUrl,
// placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
// errorholderSrc: $r('app.media.icon_failed'), errorholderSrc: $r('app.media.icon_failed'),
// downsampling: new fitter() downsampling: new fitter()
// } }
// }); });
// Button('webp') Button('webp')
// .onClick(() => { .onClick(() => {
// // this.transformSquare2(this.url); // this.transformSquare2(this.url);
// this.imageKnifeOption = { this.imageKnifeOption = {
// loadSrc: webpUrl, loadSrc: webpUrl,
// placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
// errorholderSrc: $r('app.media.icon_failed'), errorholderSrc: $r('app.media.icon_failed'),
// downsampling: new fitter() downsampling: new fitter()
// } }
// }); });
}.margin({ top: 20, bottom: 20 }) }.margin({ top: 20, bottom: 20 })
Text("降采样字节大小:" + this.bytesNumber) Text("降采样字节大小:" + this.bytesNumber)
@ -259,16 +322,16 @@ struct Index {
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.originalBytesNumber) Text("原图字节大小:" + this.originalBytesNumber)
@ -323,24 +386,24 @@ struct Index {
errorholderSrc: $r('app.media.icon_failed'), errorholderSrc: $r('app.media.icon_failed'),
} }
}); });
// Button('gif') Button('gif')
// .onClick(() => { .onClick(() => {
// // this.transformSquare2(gifUrl); // this.transformSquare2(gifUrl);
// this.imageKnifeOption = { this.imageKnifeOption = {
// loadSrc: gifUrl, loadSrc: gifUrl,
// placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
// errorholderSrc: $r('app.media.icon_failed'), errorholderSrc: $r('app.media.icon_failed'),
// } }
// }); });
// Button('webp') Button('webp')
// .onClick(() => { .onClick(() => {
// // this.transformSquare2(webpUrl); // this.transformSquare2(webpUrl);
// this.imageKnifeOption = { this.imageKnifeOption = {
// loadSrc: webpUrl, loadSrc: webpUrl,
// placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
// errorholderSrc: $r('app.media.icon_failed'), errorholderSrc: $r('app.media.icon_failed'),
// } }
// }); });
}.margin({ top: 20, bottom: 20 }) }.margin({ top: 20, bottom: 20 })
Text("降采样字节大小:" + this.bytesNumber) Text("降采样字节大小:" + this.bytesNumber)
@ -362,5 +425,12 @@ struct Index {
} }
.height('100%') .height('100%')
} }
aboutToDisappear() {
if (this.timeId !== -1) {
clearTimeout(this.timeId);
this.timeId = -1;
}
}
} }