diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 0cdad89..762ff03 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -216,6 +216,14 @@ struct IndexFunctionDemo { }).margin({ top: 15 }) }.width('100%').height(60).backgroundColor(Color.Pink) + + Text("单帧gif测试").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Button("单帧gif测试") + .onClick(() => { + router.pushUrl({ url: "pages/testSingleFrameGifPage" }); + }).margin({ top: 5, left: 3 }) + }.width('100%').height(60).backgroundColor(Color.Pink) } } .width('100%') diff --git a/entry/src/main/ets/pages/testSingleFrameGifPage.ets b/entry/src/main/ets/pages/testSingleFrameGifPage.ets new file mode 100644 index 0000000..b126aed --- /dev/null +++ b/entry/src/main/ets/pages/testSingleFrameGifPage.ets @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2021 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/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent' +import { ImageKnifeOption } from '@ohos/imageknife/src/main/ets/components/imageknife/ImageKnifeOption' + +@Entry +@Component +struct TestSingleFrameGifPage { + @State message: string = '单帧gif测试' + @State options: ImageKnifeOption = { + loadSrc: $r('app.media.app_icon') + } + + build() { + Column() { + Column() { + Text(`${this.message}`) + .width("300vp") + .height("60vp") + .textAlign(TextAlign.Center) + .fontSize("50fp") + .fontWeight(FontWeight.Bold) + Button("加载单帧gif") + .margin(16) + .onClick(() => { + console.log("liyiwei 加载单帧gif") + this.options = { + loadSrc: $r('app.media.gifSample_single_frame'), + placeholderSrc:$r('app.media.icon_loading') + } + }) + Button("加载多帧gif") + .margin(16) + .onClick(() => { + console.log("liyiwei 加载多帧gif") + this.options = { + loadSrc: $r('app.media.gifSample'), + placeholderSrc:$r('app.media.icon_loading') + } + }) + ImageKnifeComponent({ imageKnifeOption: this.options }) + .margin(16) + .width(300) + .height(300) + } + .width("100%") + .height("100%") + .justifyContent(FlexAlign.Center) + } + .width("100%") + .height("100%") + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/gifSample_single_frame.gif b/entry/src/main/resources/base/media/gifSample_single_frame.gif new file mode 100644 index 0000000..94ce8e1 Binary files /dev/null and b/entry/src/main/resources/base/media/gifSample_single_frame.gif differ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 8214dbd..63fea64 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -27,6 +27,7 @@ "pages/dataShareUriLoadPage", "pages/manyPhotoShowPage", "pages/tempUrlTestPage", - "pages/drawFactoryTestPage" + "pages/drawFactoryTestPage", + "pages/testSingleFrameGifPage" ] } diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index cdff39e..f274b1a 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -608,6 +608,10 @@ export struct ImageKnifeComponent { } // draw Frame this.drawFrame(frames, index, context, compWidth, compHeight); + //如果gif动图只有一帧的情况下,不进行后面代码的逐帧绘制循环 + if (frames.length <= 1) { + return + } // 记录渲染结束时间点 let end = new Date().getTime();