!41 解决gif图片只有1帧时因帧时间延时时间为NaN时导致图片帧不显示的问题

Merge pull request !41 from 李艺为/master
This commit is contained in:
openharmony_ci 2023-08-18 03:34:13 +00:00 committed by Gitee
commit b0562a179d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 79 additions and 1 deletions

View File

@ -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%')

View File

@ -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%")
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -27,6 +27,7 @@
"pages/dataShareUriLoadPage",
"pages/manyPhotoShowPage",
"pages/tempUrlTestPage",
"pages/drawFactoryTestPage"
"pages/drawFactoryTestPage",
"pages/testSingleFrameGifPage"
]
}

View File

@ -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();