From 618320843f2a2a47b85e27575ac9cc7a64d18b01 Mon Sep 17 00:00:00 2001 From: madixin Date: Tue, 24 Dec 2024 09:27:55 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=AD=A3decodeEndTime=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=94=99=E8=AF=AF=202.=E5=86=85=E5=AD=98=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E8=AE=B0=E5=BD=95=E5=9B=BE=E7=89=87buffersize=203.?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=8A=A0=E8=BD=BD=E5=9B=9E=E8=B0=83demo?= =?UTF-8?q?=E9=87=8C=E5=B1=95=E7=A4=BA=E5=9B=BE=E7=89=87=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E4=BA=8E=E7=BD=91=E7=BB=9C=EF=BC=8C=E6=96=87=E4=BB=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E8=BF=98=E6=98=AF=E5=86=85=E5=AD=98=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E3=80=82=20=E5=8E=BB=E9=99=A4renderTime=E7=9A=84?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=204.=E8=B0=83=E6=95=B4=E5=8A=A8=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: madixin --- CHANGELOG.md | 8 +- .../src/main/ets/pages/ImageAnimatorPage.ets | 88 ++++++++++--------- .../ets/pages/TestImageKnifeCallbackPage.ets | 50 +++-------- .../main/resources/base/element/string.json | 18 ++-- .../main/resources/zh_CN/element/string.json | 16 ++-- library/src/main/ets/ImageKnifeDispatcher.ets | 2 + library/src/main/ets/ImageKnifeLoader.ets | 2 +- 7 files changed, 85 insertions(+), 99 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd762d..fec8946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ## 3.2.0-rc.7 -- Successful callback returns httpCode +- When successfully requesting the network, return the httpcode as well - Fix bug: Network error code httpCode returns no data -- Fix bug: Height adaptation leads to fixed component height -- modify memory cache limit and file cache limit +- Modify implementation of ImageFit.Auto: do not modify image height +- Modify memory cache limit and file cache limit +- Fix record decodeEndTime in imageKinfaData +- Add image buffersize in memory cache ## 3.2.0-rc.6 - Support LogUtil to turn off log diff --git a/entry/src/main/ets/pages/ImageAnimatorPage.ets b/entry/src/main/ets/pages/ImageAnimatorPage.ets index 22b413b..622dcf9 100644 --- a/entry/src/main/ets/pages/ImageAnimatorPage.ets +++ b/entry/src/main/ets/pages/ImageAnimatorPage.ets @@ -12,83 +12,91 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AnimatorOption, ImageKnifeAnimatorComponent } from '@ohos/libraryimageknife' +import { AnimatorOption, ImageKnifeAnimatorComponent, ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component struct ImageAnimatorPage { @State animatorOption: AnimatorOption = { state: AnimationStatus.Running, - iterations: 1, - onFinish:()=>{ + iterations: -1, + onFinish: () => { console.log('ImageKnifeAnimatorComponent animatorOption onFinish') }, - onStart:()=>{ + onStart: () => { console.log('ImageKnifeAnimatorComponent animatorOption onStart') }, - onPause:()=>{ + onPause: () => { console.log('ImageKnifeAnimatorComponent animatorOption onPause') }, - onCancel:()=>{ + onCancel: () => { console.log('ImageKnifeAnimatorComponent animatorOption onCancel') }, - onRepeat:()=>{ + onRepeat: () => { console.log('ImageKnifeAnimatorComponent animatorOption onRepeat') } } - @State animatorOption1: AnimatorOption = { + @State animatorOptionFirstFrame: AnimatorOption = { state: AnimationStatus.Initial } - @State animatorOption2: AnimatorOption = { + @State animatorOptionLastFrame: AnimatorOption = { state: AnimationStatus.Initial, reverse: true } + @State imageKnifeOption: ImageKnifeOption = { + loadSrc: 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658', + placeholderSrc: $r('app.media.loading'), + errorholderSrc: $r('app.media.failed') + } + build() { - Column(){ - Flex(){ - Button($r('app.string.Play')).onClick(()=>{ + Column() { + Row() { + Button($r('app.string.Play')).onClick(() => { this.animatorOption.state = AnimationStatus.Running }) - Button($r('app.string.Pause')).onClick(()=>{ + Button($r('app.string.Pause')).onClick(() => { this.animatorOption.state = AnimationStatus.Paused }) - Button($r('app.string.Stop')).onClick(()=>{ + Button($r('app.string.Stop')).onClick(() => { this.animatorOption.state = AnimationStatus.Stopped }) - Button($r('app.string.Infinite_loop')).onClick(()=>{ + } + + Row() { + Button($r('app.string.Infinite_loop')).onClick(() => { this.animatorOption.iterations = -1 }) - Button($r('app.string.Play_once')).onClick(()=>{ + Button($r('app.string.Play_once')).onClick(() => { this.animatorOption.iterations = 1 }) - Button($r('app.string.Play_twice')).onClick(()=>{ + Button($r('app.string.Play_twice')).onClick(() => { this.animatorOption.iterations = 2 }) } + ImageKnifeAnimatorComponent({ - imageKnifeOption:{ - loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658', - placeholderSrc:$r('app.media.loading'), - errorholderSrc:$r('app.media.failed'), - border: { radius: 150 } - },animatorOption:this.animatorOption - }).width(300).height(300).backgroundColor(Color.Orange).margin({top:30}) - Text($r('app.string.Display_the_first_frame')).fontSize(20) - ImageKnifeAnimatorComponent({ - imageKnifeOption:{ - loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658', - placeholderSrc:$r('app.media.loading'), - errorholderSrc:$r('app.media.failed') - },animatorOption:this.animatorOption1 - }).width(200).height(200).backgroundColor(Color.Orange).margin({top:30}) - Text($r('app.string.Display_the_last_frame')).fontSize(20) - ImageKnifeAnimatorComponent({ - imageKnifeOption:{ - loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658', - placeholderSrc:$r('app.media.loading'), - errorholderSrc:$r('app.media.failed') - },animatorOption:this.animatorOption2 - }).width(200).height(200).backgroundColor(Color.Orange).margin({top:30}) + imageKnifeOption: this.imageKnifeOption, + animatorOption: this.animatorOption + }).width(300).height(300).backgroundColor(Color.Orange).margin({ top: 30 }) + + Row({ space: 10 }) { + Column() { + Text($r('app.string.Display_the_first_frame')).fontSize(20) + ImageKnifeAnimatorComponent({ + imageKnifeOption: this.imageKnifeOption, + animatorOption: this.animatorOptionFirstFrame + }).width(120).height(120).backgroundColor(Color.Orange) + } + + Column() { + Text($r('app.string.Display_the_last_frame')).fontSize(20) + ImageKnifeAnimatorComponent({ + imageKnifeOption: this.imageKnifeOption, + animatorOption: this.animatorOptionLastFrame + }).width(120).height(120).backgroundColor(Color.Orange) + } + }.margin({ top: 50 }).padding(10) }.width('100%').height('100%') } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets b/entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets index 06f39ba..bc6356c 100644 --- a/entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets +++ b/entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets @@ -50,8 +50,8 @@ struct TestImageKnifeCallbackPage { @State netEndTime: string | undefined = '' @State decodeStartTime: string | undefined = '' @State decodeEndTime: string | undefined = '' - @State renderTime: string | undefined = '' @State showChild: boolean = true; + @State requestFrom: string = ''; build() { Column() { @@ -76,7 +76,7 @@ struct TestImageKnifeCallbackPage { Text($r('app.string.net_end_time', this.netEndTime)).fontSize(14) Text($r('app.string.decode_start_time', this.decodeStartTime)).fontSize(14) Text($r('app.string.decode_end_time', this.decodeEndTime)).fontSize(14) - Text($r('app.string.render_time', this.renderTime)).fontSize(14) + Text($r('app.string.request_data_from', this.requestFrom)).fontSize(14) Scroll() { Column() { @@ -104,11 +104,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) @@ -134,11 +129,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) Button($r('app.string.local_pic')) @@ -163,11 +153,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) } @@ -195,11 +180,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) @@ -225,11 +205,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) Button($r('app.string.share_load_failed')) @@ -254,11 +229,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) } @@ -286,11 +256,6 @@ struct TestImageKnifeCallbackPage { } }, border: { radius: 50 }, - onComplete: (event) => { - if (event && event.loadingStatus == 0) { - this.renderTime = this.formatDate(Date.now()); - } - } } }) @@ -341,6 +306,7 @@ struct TestImageKnifeCallbackPage { this.reqStartTime = this.formatDate(data.timeInfo?.requestStartTime); this.memoryStartTime = this.formatDate(data.timeInfo?.memoryCheckStartTime); this.memoryEndTime = this.formatDate(data.timeInfo?.memoryCheckEndTime); + this.requestFrom = ''; } } @@ -360,6 +326,14 @@ struct TestImageKnifeCallbackPage { this.netEndTime = this.formatDate(data.timeInfo?.netRequestEndTime); this.decodeStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime); this.decodeEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime); + if (data.timeInfo?.netRequestEndTime !== undefined) { + this.requestFrom = 'Http request'; + } else if (data.timeInfo?.diskCheckEndTime !== undefined) { + this.requestFrom = 'File Cache'; + } else { + this.requestFrom = 'Memory Cache'; + } + } } @@ -377,6 +351,7 @@ struct TestImageKnifeCallbackPage { this.decodeStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime); this.decodeEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime); this.reqCancelTime = this.formatDate(data.timeInfo?.requestCancelTime) + this.requestFrom = ''; } } @@ -407,7 +382,6 @@ struct TestImageKnifeCallbackPage { this.netEndTime = '' this.decodeStartTime = '' this.decodeEndTime = '' - this.renderTime = '' this.showChild = true; } } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index ed78ad0..19d4cfc 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -110,11 +110,11 @@ }, { "name": "Display_the_first_frame", - "value": "Display the first frame of the animation" + "value": "first frame" }, { "name": "Display_the_last_frame", - "value": "Display the last frame of the animation" + "value": "last frame" }, { "name": "Play", @@ -582,11 +582,11 @@ }, { "name": "img_frame", - "value": "the number of frames of the picture:%d " + "value": "the frames of the animator:%d " }, { "name": "img_content_size", - "value": "picture decoded width and height size:%s " + "value": "decoded width and height size of image:%s " }, { "name": "err_msg", @@ -606,15 +606,15 @@ }, { "name": "req_start_time", - "value": "image request start time point:%s " + "value": "request start time:%s " }, { "name": "req_end_time", - "value": "the point in time at which the image request ends:%s " + "value": "request end time:%s " }, { "name": "req_cancel_time", - "value": "the point at which the image request is cancelled:%s " + "value": "request cancel time:%s " }, { "name": "memory_start_time", @@ -649,8 +649,8 @@ "value": "decoding end time point:%s " }, { - "name": "render_time", - "value": "render successful time:%s " + "name": "request_data_from", + "value": "request from:%s " }, { "name": "Image_Downsampling_Functionality", diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 35f0c99..d65db7d 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -106,11 +106,11 @@ }, { "name": "Display_the_first_frame", - "value": "动画显示第一帧" + "value": "第一帧" }, { "name": "Display_the_last_frame", - "value": "动画显示最后一帧" + "value": "最后一帧" }, { "name": "Play", @@ -574,7 +574,7 @@ }, { "name": "img_frame", - "value": "图片的帧数:%d " + "value": "动图帧数:%d " }, { "name": "img_content_size", @@ -598,15 +598,15 @@ }, { "name": "req_start_time", - "value": "图片的请求开始时间点:%s " + "value": "请求开始时间:%s " }, { "name": "req_end_time", - "value": "图片请求结束的时间点:%s " + "value": "请求结束时间:%s " }, { "name": "req_cancel_time", - "value": "图片请求取消的时间点:%s " + "value": "请求取消时间:%s " }, { "name": "memory_start_time", @@ -641,8 +641,8 @@ "value": "解码结束时间点:%s " }, { - "name": "render_time", - "value": "渲染成功的时间:%s " + "name": "request_data_from", + "value": "请求数据来自于:%s " }, { "name": "Image_Downsampling_Functionality", diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 37a399a..d7c5918 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -115,6 +115,7 @@ export class ImageKnifeDispatcher { target.imageWidth = memoryCache.imageWidth; target.imageHeight = memoryCache.imageHeight; target.type = memoryCache.type; + target.bufSize = memoryCache.bufSize target.imageAnimator = memoryCache.imageAnimator; } @@ -425,6 +426,7 @@ export class ImageKnifeDispatcher { imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width, imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height, type: requestJobResult.type, + bufSize: requestJobResult.bufferSize, imageAnimator: imageKnifeData.imageAnimator } diff --git a/library/src/main/ets/ImageKnifeLoader.ets b/library/src/main/ets/ImageKnifeLoader.ets index c6135ba..4b9affc 100644 --- a/library/src/main/ets/ImageKnifeLoader.ets +++ b/library/src/main/ets/ImageKnifeLoader.ets @@ -312,7 +312,7 @@ export class ImageKnifeLoader { } else { timeInfo.decodeStartTime = Date.now() let base64str = 'data:image/' + typeValue + ';base64,' + new util.Base64Helper().encodeToStringSync(new Uint8Array(resBuf)) - timeInfo.diskCheckEndTime = Date.now() + timeInfo.decodeEndTime = Date.now() let res: RequestJobResult = { pixelMap: base64str, bufferSize: resBuf.byteLength,