webp图片,实现首页轮盘动画
Signed-off-by: 'LuQian-KUN' <gaopengcheng11@h-partners.com>
This commit is contained in:
parent
b7eae6eefb
commit
c68ef7f8ad
|
@ -292,6 +292,10 @@ struct IndexFunctionDemo {
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.pushUrl({ url: "pages/testSingleFrameGifPage" });
|
router.pushUrl({ url: "pages/testSingleFrameGifPage" });
|
||||||
}).margin({ top: 5, left: 3 })
|
}).margin({ top: 5, left: 3 })
|
||||||
|
Button("webp测试")
|
||||||
|
.onClick(() => {
|
||||||
|
router.pushUrl({ url: "pages/webpImageTestPage" });
|
||||||
|
}).margin({ top: 5, left: 3 })
|
||||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||||
|
|
||||||
Text("worker测试").fontSize(15)
|
Text("worker测试").fontSize(15)
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* 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/libraryimageknife'
|
||||||
|
import { ImageKnifeOption,ScaleType } from '@ohos/libraryimageknife'
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct webpImageTestPage {
|
||||||
|
@State message: string = 'webp图片'
|
||||||
|
@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("加载单帧webp")
|
||||||
|
.margin(16)
|
||||||
|
.onClick(() => {
|
||||||
|
console.log("加载单帧webp")
|
||||||
|
this.options = {
|
||||||
|
loadSrc: $r('app.media.webpxingkong'),
|
||||||
|
placeholderSrc:$r('app.media.icon_loading'),
|
||||||
|
mainScaleType:ScaleType.FIT_XY
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Button("加载多帧webp")
|
||||||
|
.margin(16)
|
||||||
|
.onClick(() => {
|
||||||
|
console.log("加载多帧webp")
|
||||||
|
this.options = {
|
||||||
|
loadSrc: $r('app.media.webpXin'),
|
||||||
|
placeholderSrc:$r('app.media.icon_loading'),
|
||||||
|
mainScaleType:ScaleType.FIT_XY
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ImageKnifeComponent({ imageKnifeOption: this.options })
|
||||||
|
.margin(16)
|
||||||
|
.width(200)
|
||||||
|
.height(100)
|
||||||
|
.clip(true)
|
||||||
|
.borderRadius(50)
|
||||||
|
}
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
.justifyContent(FlexAlign.Center)
|
||||||
|
}
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 510 KiB |
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
|
@ -48,6 +48,7 @@
|
||||||
"pages/testImageKnifeAutoHeightPage",
|
"pages/testImageKnifeAutoHeightPage",
|
||||||
"pages/testPriorityComponent",
|
"pages/testPriorityComponent",
|
||||||
"pages/testReusePhotoPage",
|
"pages/testReusePhotoPage",
|
||||||
"pages/testImageKnifeCache"
|
"pages/testImageKnifeCache",
|
||||||
|
"pages/webpImageTestPage"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -387,7 +387,7 @@ export class ImageKnife {
|
||||||
onError('暂不支持的类型!类型=' + filetype);
|
onError('暂不支持的类型!类型=' + filetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImageKnifeData.GIF == filetype && !request.dontAnimateFlag) {
|
if ((ImageKnifeData.GIF == filetype || ImageKnifeData.WEBP == filetype) && !request.dontAnimateFlag) {
|
||||||
let gifParseImpl = new GIFParseImpl()
|
let gifParseImpl = new GIFParseImpl()
|
||||||
gifParseImpl.parseGifs(cached, (data?: GIFFrame[], err?: BusinessError | string) => {
|
gifParseImpl.parseGifs(cached, (data?: GIFFrame[], err?: BusinessError | string) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -159,8 +159,8 @@ export class RequestManager {
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(arrayBuffer)
|
let typeValue = fileTypeUtil.getFileType(arrayBuffer)
|
||||||
LogUtil.log("ImageKnife RequestManager - 文件类型为= " + typeValue)
|
LogUtil.log("ImageKnife RequestManager - 文件类型为= " + typeValue)
|
||||||
// gif处理
|
// gif、webp处理
|
||||||
if (ImageKnifeData.GIF == typeValue && !request.dontAnimateFlag) {
|
if ((ImageKnifeData.GIF == typeValue || ImageKnifeData.WEBP == typeValue) && !request.dontAnimateFlag) {
|
||||||
// 处理gif
|
// 处理gif
|
||||||
this.gifProcess(onComplete, onError, arrayBuffer, typeValue)
|
this.gifProcess(onComplete, onError, arrayBuffer, typeValue)
|
||||||
} else if (ImageKnifeData.SVG == typeValue) {
|
} else if (ImageKnifeData.SVG == typeValue) {
|
||||||
|
@ -258,8 +258,8 @@ export class RequestManager {
|
||||||
// 步骤一:文件转为pixelMap 然后变换 给Image组件
|
// 步骤一:文件转为pixelMap 然后变换 给Image组件
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(source);
|
let typeValue = fileTypeUtil.getFileType(source);
|
||||||
// 解析磁盘文件 gif 和 svg
|
// 解析磁盘文件 gif、webp 和 svg
|
||||||
if (ImageKnifeData.GIF == typeValue && !request.dontAnimateFlag) {
|
if ((ImageKnifeData.GIF == typeValue || ImageKnifeData.WEBP == typeValue) && !request.dontAnimateFlag) {
|
||||||
// 处理gif
|
// 处理gif
|
||||||
this.gifProcess(onComplete, onError, source, typeValue)
|
this.gifProcess(onComplete, onError, source, typeValue)
|
||||||
} else if (ImageKnifeData.SVG == typeValue) {
|
} else if (ImageKnifeData.SVG == typeValue) {
|
||||||
|
|
Loading…
Reference in New Issue