跳过网络,从内存中取图片,接口说明文档

Signed-off-by: ‘面条侠’ <‘wangxinxin51@h-partners.com’>
This commit is contained in:
‘面条侠’ 2024-04-07 15:42:30 +08:00
parent 021a6e42f6
commit 4fba7e9191
1 changed files with 37 additions and 45 deletions

View File

@ -54,57 +54,50 @@ struct testImageKnifeCache {
placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed') errorholderSrc: $r('app.media.icon_failed')
}; };
loadSuccess = (data: ImageKnifeData) => {
hasUrlCache(url: string, cacheType: CacheType = CacheType.Default, size: Size = { clearTimeout(this.timeId);
width: 0, if (data.isPixelMap()) {
height: 0 if (data.drawPixelMap) {
}) { let pixelmap = data.drawPixelMap.imagePixelMap
imageKnife?.isUrlExist(url, cacheType, size).then((data: ImageKnifeData) => { if (pixelmap) {
clearTimeout(this.timeId); if (this.index_ == 1) {
if (data.isPixelMap()) { this.imagePixelMap = pixelmap;
if (data.drawPixelMap) { } else if (this.index_ == 2) {
let pixelmap = data.drawPixelMap.imagePixelMap this.imagePixelMap_ = pixelmap;
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.isGIFFrame()) {
if (data.drawGIFFrame) { let index: number = 0
if (data.drawGIFFrame.imageGIFFrames) { if (data.drawGIFFrame) {
let renderGif = () => { if (data.drawGIFFrame.imageGIFFrames) {
if (data.drawGIFFrame) { let renderGif = () => {
if (data.drawGIFFrame.imageGIFFrames) { if (data.drawGIFFrame) {
let pixelmap = data.drawGIFFrame.imageGIFFrames[index].drawPixelMap if (data.drawGIFFrame.imageGIFFrames) {
let delay = data.drawGIFFrame.imageGIFFrames[index].delay let pixelmap = data.drawGIFFrame.imageGIFFrames[index].drawPixelMap
if (pixelmap) { let delay = data.drawGIFFrame.imageGIFFrames[index].delay
if (this.index_ == 1) { if (pixelmap) {
this.imagePixelMap = pixelmap; if (this.index_ == 1) {
} else if (this.index_ == 2) { this.imagePixelMap = pixelmap;
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() { build() {
@ -192,20 +185,19 @@ struct testImageKnifeCache {
Button('缓存图片') Button('缓存图片')
.onClick(() => { .onClick(() => {
this.index_ = 1; this.index_ = 1;
this.hasUrlCache(this.url, CacheType.Cache, this.comSize); imageKnife?.isUrlExist(this.url, CacheType.Cache, this.comSize);
}) })
Button('磁盘图片') Button('磁盘图片')
.onClick(() => { .onClick(() => {
this.index_ = 2; this.index_ = 2;
this.hasUrlCache(this.url, CacheType.Disk, this.comSize); imageKnife?.isUrlExist(this.url, CacheType.Disk, this.comSize);
}) })
Button('默认') Button('默认')
.onClick(() => { .onClick(() => {
this.index_ = 2; this.index_ = 2;
this.hasUrlCache(this.url); imageKnife?.isUrlExist(this.url);
}) })
} }