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