diff --git a/CHANGELOG.md b/CHANGELOG.md index b37b517..2c5d7cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 3.0.1-rc.2 - 修复自定义下载失败无失败回调 - 增加全局配置自定义下载接口 +- 修复主图相同,错误图不同导致只显示一个错误图 +- heic格式图片文件魔数从第五位开始匹配 ## 3.0.1-rc.1 - 新增ImageKnifeAnimatorComponent控制动图组件 diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 06da551..3383f6a 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -141,7 +141,12 @@ struct Index { uri: 'pages/TestRemoveCache', }); }) + Button("测试错误图显示").margin({top:10}).onClick(()=>{ + router.push({ + uri: 'pages/TestErrorHolderPage', + }); + }) Button("测试媒体url").margin({top:10}).onClick(()=>{ router.push({ uri: 'pages/dataShareUriLoadPage', diff --git a/entry/src/main/ets/pages/TestErrorHolderPage.ets b/entry/src/main/ets/pages/TestErrorHolderPage.ets new file mode 100644 index 0000000..f49ab6c --- /dev/null +++ b/entry/src/main/ets/pages/TestErrorHolderPage.ets @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ImageKnifeComponent } from '@ohos/libraryimageknife' + +@Entry +@Component +struct TestErrorHolderPage { + + build() { + Column() { + Text("ImageKnifeComponent1").fontSize(20) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: "abc", + errorholderSrc:$r('app.media.failed') + } + }).width(200).height(200) + Text("ImageKnifeComponent2").fontSize(20) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: "abc", + errorholderSrc:$r('app.media.startIcon') + } + }).width(200).height(200) + Text("ImageKnifeComponent2").fontSize(20) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: "abc", + errorholderSrc:$r('app.media.mask_starfish') + } + }).width(200).height(200) + } + .height('100%') .width('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 2b6e3e7..42b571c 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -21,6 +21,7 @@ "pages/dataShareUriLoadPage", "pages/TestCommonImage", "pages/ImageAnimatorPage", - "pages/TestSetCustomImagePage" + "pages/TestSetCustomImagePage", + "pages/TestErrorHolderPage" ] } \ No newline at end of file diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 86ac447..795d709 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -255,9 +255,9 @@ export class ImageKnifeDispatcher { if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.errorholderSrc !== undefined) { - if (this.showFromMemomry(currentRequest, requestWithSource.request.imageKnifeOption.errorholderSrc, + if (this.showFromMemomry(requestWithSource.request, requestWithSource.request.imageKnifeOption.errorholderSrc, ImageKnifeRequestSource.ERROR_HOLDER) === false) { - this.getAndShowImage(currentRequest, requestWithSource.request.imageKnifeOption.errorholderSrc, + this.getAndShowImage(requestWithSource.request, requestWithSource.request.imageKnifeOption.errorholderSrc, ImageKnifeRequestSource.ERROR_HOLDER); } } diff --git a/library/src/main/ets/utils/FileTypeUtil.ets b/library/src/main/ets/utils/FileTypeUtil.ets index 44ada15..7627162 100644 --- a/library/src/main/ets/utils/FileTypeUtil.ets +++ b/library/src/main/ets/utils/FileTypeUtil.ets @@ -58,7 +58,7 @@ export class FileTypeUtil { const bufferList = this.fileSignatureMap[fileType]; for (let i = 0; i < bufferList.length; i++) { let signature = bufferList[i]; - if (this.matchesSignature(fileData, signature)) { + if (this.matchesSignature(fileData, signature,fileType)) { hasMatched = true; matchedFileType = fileType; break @@ -75,12 +75,12 @@ export class FileTypeUtil { } - matchesSignature(fileData: Uint8Array, signature: Uint8Array): boolean { + matchesSignature(fileData: Uint8Array, signature: Uint8Array,fileType:string): boolean { if (fileData.length < signature.length) { return false; // 文件长度不足,无法匹配魔数 } - for (let i = 0; i < signature.length; i++) { + for (let i = fileType == "heic" ? 4 : 0; i < signature.length; i++) { if (fileData[i] !== signature[i]) { return false; // 魔数不匹配 }