From 150b75fe8c3bad558dfc2e32cbf0484f3e1e4e24 Mon Sep 17 00:00:00 2001 From: zgf Date: Fri, 14 Jun 2024 16:41:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?svg=E8=A7=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E9=A2=84=E5=8A=A0=E8=BD=BD=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=8C=E6=96=87=E4=BB=B6=E7=BC=93=E5=AD=98=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 5 +++++ library/oh-package.json5 | 2 +- library/src/main/ets/ImageKnife.ets | 14 +++++++++----- library/src/main/ets/ImageKnifeDispatcher.ets | 15 ++++++++------- library/src/main/ets/model/ImageKnifeData.ets | 1 + library/src/main/ets/utils/FileCache.ets | 18 +++++++++++------- .../src/main/ets/pages/InitImageKnife.ets | 2 +- 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f17062..843383b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.0-rc.8 +- svg解码单位改为px +- 修复预加载接口preLoadCache传ImageKnifeOption失效 +- 文件缓存初始化接口新增目录参数 + ## 3.0.0-rc.7 - 修复成功回调获取不到宽高 - 新增svg图片解码 diff --git a/library/oh-package.json5 b/library/oh-package.json5 index a584ba0..c206a0f 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-tpc/ImageKnife", "type": "module", - "version": "3.0.0-rc.7", + "version": "3.0.0-rc.8", "dependencies": { "@ohos/gpu_transform": "^1.0.2" }, diff --git a/library/src/main/ets/ImageKnife.ets b/library/src/main/ets/ImageKnife.ets index 19b4d08..e58fadd 100644 --- a/library/src/main/ets/ImageKnife.ets +++ b/library/src/main/ets/ImageKnife.ets @@ -65,9 +65,13 @@ export class ImageKnife { * @param size 缓存数量 * @param memory 内存大小 */ - async initFileCache(context: Context, size: number = 256, memory: number = 256 * 1024 * 1024) { + async initFileCache(context: Context, size: number = 256, memory: number = 256 * 1024 * 1024,path?: string) { this.fileCache = new FileCache(context, size, memory) - await this.fileCache.initFileCache() + if ( path != undefined ) { + await this.fileCache.initFileCache(path) + } else { + await this.fileCache.initFileCache() + } } /** @@ -166,10 +170,10 @@ export class ImageKnife { preLoadCache(loadSrc: string | ImageKnifeOption): Promise { return new Promise((resolve, reject) => { let imageKnifeOption = new ImageKnifeOption() - if (loadSrc instanceof ImageKnifeOption) { - imageKnifeOption = loadSrc + if (typeof loadSrc == "string") { + imageKnifeOption.loadSrc = loadSrc } else { - imageKnifeOption.loadSrc = loadSrc; + imageKnifeOption = loadSrc; } LogUtil.log("ImageKnife_DataTime_preLoadCache-imageKnifeOption:"+loadSrc) let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature) diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 56b81c3..03d7a70 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -171,7 +171,8 @@ export class ImageKnifeDispatcher { signature: currentRequest.imageKnifeOption.signature, requestSource: requestSource, isWatchProgress: isWatchProgress, - memoryKey: memoryKey + memoryKey: memoryKey, + fileCacheFolder: ImageKnife.getInstance().getFileCache().getCacheFolder() } @@ -373,7 +374,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List Date: Fri, 14 Jun 2024 16:43:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?svg=E8=A7=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E9=A2=84=E5=8A=A0=E8=BD=BD=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=8C=E6=96=87=E4=BB=B6=E7=BC=93=E5=AD=98=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- entry/src/main/ets/pages/TestPrefetchToFileCache.ets | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/TestPrefetchToFileCache.ets b/entry/src/main/ets/pages/TestPrefetchToFileCache.ets index d6b9e23..eb735a7 100644 --- a/entry/src/main/ets/pages/TestPrefetchToFileCache.ets +++ b/entry/src/main/ets/pages/TestPrefetchToFileCache.ets @@ -26,11 +26,18 @@ struct TestPrefetchToFileCachePage { let fileCachePath = await ImageKnife.getInstance().preLoadCache(url) console.log("preload-fileCachePath=="+ fileCachePath) } + async preload1(url:string) { + let fileCachePath = await ImageKnife.getInstance().preLoadCache({ loadSrc: url }) + console.log("preload-fileCachePath1=="+ fileCachePath) + } build() { Column() { - Button("预加载图片到文件缓存").margin({top:10}).onClick(async ()=>{ + Button("url预加载图片到文件缓存").margin({top:10}).onClick(async ()=>{ await this.preload("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658") }) + Button("option预加载图片到文件缓存").margin({top:10}).onClick(async ()=>{ + await this.preload1("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658") + }) Button("加载图片(预加载后可断网加载)").margin({top:10}).onClick(()=>{ this.imageKnifeOption.loadSrc = "https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658" })