From e48600fe7f7c64b0c125976540b85ce9825739a9 Mon Sep 17 00:00:00 2001 From: chongtiantian Date: Mon, 1 Jul 2024 16:07:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9uuid=E7=9A=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8=E8=B5=84?= =?UTF-8?q?=E6=BA=90loadSrc=EF=BC=8C=E5=AE=BD=E9=AB=98=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=95=88=E6=9E=9C=E7=9A=84=E6=8B=BC=E6=8E=A5?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=BD=9C=E4=B8=BA=E5=85=A5=E5=8F=82?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=90=8C=E8=B5=84=E6=BA=90=E5=9B=BE?= =?UTF-8?q?=E5=BD=A2=E8=BD=AC=E6=8D=A2=E9=94=99=E4=B9=B1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chongtiantian --- CHANGELOG.md | 1 + entry/src/main/ets/pages/transformsPage.ets | 33 +++++++++++++++++++ .../imageknife/ImageKnifeComponent.ets | 3 +- .../components/imageknife/RequestOption.ets | 6 +++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6aeb1e..f0f778c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 2.3.0-rc.1 - 修复file://格式图片无法显示 +- 修改uuid的生成方式,使用资源loadSrc,宽高以及转换效果的拼接字符串作为入参, 修复同资源图形转换错乱的问题 ## 2.3.0-rc.0 - 增加gif图duration的默认值,以及默认播放次数 diff --git a/entry/src/main/ets/pages/transformsPage.ets b/entry/src/main/ets/pages/transformsPage.ets index 7804142..e06f22c 100644 --- a/entry/src/main/ets/pages/transformsPage.ets +++ b/entry/src/main/ets/pages/transformsPage.ets @@ -47,6 +47,12 @@ struct transformsPage { placeholderSrc: $r('app.media.icon_loading'), errorholderSrc: $r('app.media.icon_failed') }; + @State option1: ImageKnifeOption = { + loadSrc: $r('app.media.pngSample'), + } + @State option2: ImageKnifeOption = { + loadSrc: $r('app.media.pngSample'), + } private transformations: Array> = new Array(); private blurTransformation: BlurTransformation = new BlurTransformation(15, 3); private brightnessFilterTransformation: BrightnessFilterTransformation = new BrightnessFilterTransformation(0.5); @@ -452,6 +458,33 @@ struct transformsPage { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption }).width(300).height(300) }.width(400).height(400).margin({ top: 10 }).backgroundColor(Color.Pink) + + Button("同资源不同转换效果").onClick(() => { + this.option1 = { + loadSrc: $r('app.media.pngSample'), + errorholderSrc: $r("app.media.app_icon"), + transformation: new CropCircleTransformation() + } + this.option2 = { + loadSrc: $r('app.media.pngSample'), + errorholderSrc: $r("app.media.app_icon"), + transformations: [new RotateImageTransformation(45), new InvertFilterTransformation()] + } + }).margin(10).backgroundColor(Color.Blue) + Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) { + ImageKnifeComponent({ + imageKnifeOption: this.option1 + }).width(300) + .height(300) + .margin(10) + .borderWidth(3) + ImageKnifeComponent({ + imageKnifeOption: this.option2 + }).width(300) + .height(300) + .margin(10) + .borderWidth(3) + } } } .width('100%') diff --git a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 436ca30..2b3e795 100644 --- a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -404,11 +404,12 @@ export struct ImageKnifeComponent { this.lastSrc = this.imageKnifeOption.loadSrc; } this.detachFromLayout = this.request.detachFromLayout; + // 先配置request的属性 + this.configDisplay(this.request); if (this.request.loadSrc!=this.lastSrc) { this.configNecessary(this.request); } this.configCacheStrategy(this.request); - this.configDisplay(this.request); this.configHspContext(this.request); this.configRenderGpu(this.request); let imageKnife: ImageKnife | undefined = ImageKnifeGlobal?.getInstance()?.getImageKnife(); diff --git a/library/src/main/ets/components/imageknife/RequestOption.ets b/library/src/main/ets/components/imageknife/RequestOption.ets index ac7695e..54632fb 100644 --- a/library/src/main/ets/components/imageknife/RequestOption.ets +++ b/library/src/main/ets/components/imageknife/RequestOption.ets @@ -208,7 +208,11 @@ export class RequestOption { this.transformations = array; } generateUUID(): string { - return SparkMD5.hashBinary(JSON.stringify(this.loadSrc)) as string; + let content: string = JSON.stringify(this.loadSrc) + ',' + this.size.width + ',' + this.size.height; + if (this.transformations.length) { + content += JSON.stringify(this.transformations); + } + return SparkMD5.hashBinary(content); } setModuleContext(moduleCtx: common.UIAbilityContext) {