From 4fba7e9191aadc29492eea16abe7c6d6d448da14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98=E9=9D=A2=E6=9D=A1=E4=BE=A0=E2=80=99?= <‘wangxinxin51@h-partners.com’> Date: Sun, 7 Apr 2024 15:42:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BF=87=E7=BD=91=E7=BB=9C=EF=BC=8C?= =?UTF-8?q?=E4=BB=8E=E5=86=85=E5=AD=98=E4=B8=AD=E5=8F=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=EF=BC=8C=E6=8E=A5=E5=8F=A3=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’> --- .../main/ets/pages/testImageKnifeCache.ets | 82 +++++++++---------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/entry/src/main/ets/pages/testImageKnifeCache.ets b/entry/src/main/ets/pages/testImageKnifeCache.ets index ca4de4f..5d6bad0 100644 --- a/entry/src/main/ets/pages/testImageKnifeCache.ets +++ b/entry/src/main/ets/pages/testImageKnifeCache.ets @@ -54,57 +54,50 @@ struct testImageKnifeCache { placeholderSrc: $r('app.media.icon_loading'), errorholderSrc: $r('app.media.icon_failed') }; - - hasUrlCache(url: string, cacheType: CacheType = CacheType.Default, size: Size = { - width: 0, - height: 0 - }) { - imageKnife?.isUrlExist(url, cacheType, size).then((data: ImageKnifeData) => { - clearTimeout(this.timeId); - if (data.isPixelMap()) { - if (data.drawPixelMap) { - let pixelmap = data.drawPixelMap.imagePixelMap - if (pixelmap) { - if (this.index_ == 1) { - this.imagePixelMap = pixelmap; - } else if (this.index_ == 2) { - this.imagePixelMap_ = pixelmap; - } + loadSuccess = (data: ImageKnifeData) => { + clearTimeout(this.timeId); + if (data.isPixelMap()) { + if (data.drawPixelMap) { + let pixelmap = data.drawPixelMap.imagePixelMap + if (pixelmap) { + if (this.index_ == 1) { + this.imagePixelMap = pixelmap; + } else if (this.index_ == 2) { + this.imagePixelMap_ = pixelmap; } } } - if (data.isGIFFrame()) { - 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) { - if (this.index_ == 1) { - this.imagePixelMap = pixelmap; - } else if (this.index_ == 2) { - this.imagePixelMap_ = pixelmap; - } + } + if (data.isGIFFrame()) { + 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) { + if (this.index_ == 1) { + this.imagePixelMap = pixelmap; + } else if (this.index_ == 2) { + this.imagePixelMap_ = pixelmap; } - index++; - if (index == data.drawGIFFrame.imageGIFFrames.length - 1) { - index = 0 - } - this.timeId = setTimeout(renderGif, data!.drawGIFFrame!.imageGIFFrames![index].delay) } + index++; + if (index == data.drawGIFFrame.imageGIFFrames.length - 1) { + index = 0 + } + this.timeId = setTimeout(renderGif, data!.drawGIFFrame!.imageGIFFrames![index].delay) } } - renderGif() } + renderGif() } } - }).catch((err: BusinessError) => { - - }); - + } + } + loadError = (err: BusinessError) => { } build() { @@ -192,20 +185,19 @@ struct testImageKnifeCache { Button('缓存图片') .onClick(() => { this.index_ = 1; - this.hasUrlCache(this.url, CacheType.Cache, this.comSize); - + imageKnife?.isUrlExist(this.url, CacheType.Cache, this.comSize); }) Button('磁盘图片') .onClick(() => { this.index_ = 2; - this.hasUrlCache(this.url, CacheType.Disk, this.comSize); + imageKnife?.isUrlExist(this.url, CacheType.Disk, this.comSize); }) Button('默认') .onClick(() => { this.index_ = 2; - this.hasUrlCache(this.url); + imageKnife?.isUrlExist(this.url); }) }