新增多线程优先级
Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
2cfbabb3ec
commit
3d3e02bf1d
|
@ -7,6 +7,9 @@
|
||||||
- ImageKnife新增图片宽高自适应功能
|
- ImageKnife新增图片宽高自适应功能
|
||||||
- 修复onlyRetrieveFromCache属性(仅磁盘和内存获取资源)失效
|
- 修复onlyRetrieveFromCache属性(仅磁盘和内存获取资源)失效
|
||||||
- 修改拼写错误
|
- 修改拼写错误
|
||||||
|
- 新增多线程优先级
|
||||||
|
- 修复复用场景下图片闪动以及概率错位
|
||||||
|
- 获取组件宽高改为使用CanvasRenderingContext2D对象获取宽高,并修复改变字体大小导致部分图片消失
|
||||||
|
|
||||||
## 2.1.2-rc.10
|
## 2.1.2-rc.10
|
||||||
- 修复部分gif图片识别成静态图
|
- 修复部分gif图片识别成静态图
|
||||||
|
|
|
@ -35,7 +35,11 @@ struct IndexFunctionDemo {
|
||||||
console.log("测试文件子系统")
|
console.log("测试文件子系统")
|
||||||
router.pushUrl({ url: "pages/basicTestFileIOPage" });
|
router.pushUrl({ url: "pages/basicTestFileIOPage" });
|
||||||
}).margin({ top: 5, left: 3 })
|
}).margin({ top: 5, left: 3 })
|
||||||
|
Button("优先级加载")
|
||||||
|
.onClick(() => {
|
||||||
|
console.log("优先级加载")
|
||||||
|
router.pushUrl({ url: "pages/testPriorityComponent" });
|
||||||
|
}).margin({ top: 5, left: 3 })
|
||||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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 , Priority , NONE } from '@ohos/libraryimageknife'
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct TestPriorityComponent {
|
||||||
|
private data: string[] = [
|
||||||
|
"http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg",
|
||||||
|
"http://c.hiphotos.baidu.com/image/pic/item/30adcbef76094b36de8a2fe5a1cc7cd98d109d99.jpg",
|
||||||
|
"http://h.hiphotos.baidu.com/image/pic/item/7c1ed21b0ef41bd5f2c2a9e953da81cb39db3d1d.jpg",
|
||||||
|
"http://g.hiphotos.baidu.com/image/pic/item/55e736d12f2eb938d5277fd5d0628535e5dd6f4a.jpg",
|
||||||
|
"http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg",
|
||||||
|
"http://b.hiphotos.baidu.com/image/pic/item/9d82d158ccbf6c81b94575cfb93eb13533fa40a2.jpg",
|
||||||
|
"http://e.hiphotos.baidu.com/image/pic/item/4bed2e738bd4b31c1badd5a685d6277f9e2ff81e.jpg",
|
||||||
|
"http://g.hiphotos.baidu.com/image/pic/item/0d338744ebf81a4c87a3add4d52a6059252da61e.jpg",
|
||||||
|
"http://a.hiphotos.baidu.com/image/pic/item/f2deb48f8c5494ee5080c8142ff5e0fe99257e19.jpg",
|
||||||
|
"http://f.hiphotos.baidu.com/image/pic/item/4034970a304e251f503521f5a586c9177e3e53f9.jpg",
|
||||||
|
"http://b.hiphotos.baidu.com/image/pic/item/279759ee3d6d55fbb3586c0168224f4a20a4dd7e.jpg",
|
||||||
|
"http://img2.xkhouse.com/bbs/hfhouse/data/attachment/forum/corebbs/2009-11/2009113011534566298.jpg",
|
||||||
|
"http://a.hiphotos.baidu.com/image/pic/item/e824b899a9014c087eb617650e7b02087af4f464.jpg",
|
||||||
|
"http://c.hiphotos.baidu.com/image/pic/item/9c16fdfaaf51f3de1e296fa390eef01f3b29795a.jpg",
|
||||||
|
"http://d.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01f119945cbe2fe9925bc317d2a.jpg",
|
||||||
|
"http://h.hiphotos.baidu.com/image/pic/item/902397dda144ad340668b847d4a20cf430ad851e.jpg",
|
||||||
|
"http://b.hiphotos.baidu.com/image/pic/item/359b033b5bb5c9ea5c0e3c23d139b6003bf3b374.jpg",
|
||||||
|
"http://a.hiphotos.baidu.com/image/pic/item/8d5494eef01f3a292d2472199d25bc315d607c7c.jpg",
|
||||||
|
"http://b.hiphotos.baidu.com/image/pic/item/e824b899a9014c08878b2c4c0e7b02087af4f4a3.jpg",
|
||||||
|
"http://g.hiphotos.baidu.com/image/pic/item/6d81800a19d8bc3e770bd00d868ba61ea9d345f2.jpg",
|
||||||
|
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||||
|
'https://img-blog.csdnimg.cn/20191215043500229.png',
|
||||||
|
'https://img-blog.csdn.net/20140514114029140',
|
||||||
|
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp'
|
||||||
|
]
|
||||||
|
|
||||||
|
build(){
|
||||||
|
Column(){
|
||||||
|
Grid(){
|
||||||
|
ForEach(this.data,(item:string,index:number)=>{
|
||||||
|
GridItem(){
|
||||||
|
if(index % 2 == 0){
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc:item,
|
||||||
|
placeholderSrc:$r('app.media.icon_loading'),
|
||||||
|
strategy:new NONE(),
|
||||||
|
isCacheable:false,
|
||||||
|
priority:Priority.LOW
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (index % 3 == 0) {
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc:item,
|
||||||
|
placeholderSrc:$r('app.media.icon_loading'),
|
||||||
|
strategy:new NONE(),
|
||||||
|
isCacheable:false,
|
||||||
|
priority:Priority.MEDIUM
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc:item,
|
||||||
|
placeholderSrc:$r('app.media.icon_loading'),
|
||||||
|
strategy:new NONE(),
|
||||||
|
isCacheable:false,
|
||||||
|
priority:Priority.HIGH
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
.columnsTemplate("1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr")
|
||||||
|
.rowsTemplate("1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr")
|
||||||
|
.columnsGap(10)
|
||||||
|
.backgroundColor(0xFAEEE0)
|
||||||
|
}.width("100%").height("100%").backgroundColor(Color.Pink)
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,7 @@
|
||||||
"pages/testImageKnifeHttpRequestHeader",
|
"pages/testImageKnifeHttpRequestHeader",
|
||||||
"pages/testImageKnifeAutoPage",
|
"pages/testImageKnifeAutoPage",
|
||||||
"pages/testImageKnifeAutoWidthPage",
|
"pages/testImageKnifeAutoWidthPage",
|
||||||
"pages/testImageKnifeAutoHeightPage"
|
"pages/testImageKnifeAutoHeightPage",
|
||||||
|
"pages/testPriorityComponent"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -98,7 +98,7 @@ export { UPNG } from './src/main/ets/components/3rd_party/upng/UPNG'
|
||||||
export { ImageKnife } from './src/main/ets/components/imageknife/ImageKnife'
|
export { ImageKnife } from './src/main/ets/components/imageknife/ImageKnife'
|
||||||
export { ImageKnifeGlobal } from './src/main/ets/components/imageknife/ImageKnifeGlobal'
|
export { ImageKnifeGlobal } from './src/main/ets/components/imageknife/ImageKnifeGlobal'
|
||||||
export { ObjectKey } from './src/main/ets/components/imageknife/ObjectKey'
|
export { ObjectKey } from './src/main/ets/components/imageknife/ObjectKey'
|
||||||
export {RequestOption,Size,DetachFromLayout} from './src/main/ets/components/imageknife/RequestOption'
|
export {RequestOption,Size,DetachFromLayout,Priority} from './src/main/ets/components/imageknife/RequestOption'
|
||||||
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||||
export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'
|
export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'
|
||||||
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from './src/main/ets/components/imageknife/ImageKnifeOption'
|
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from './src/main/ets/components/imageknife/ImageKnifeOption'
|
||||||
|
|
|
@ -540,6 +540,7 @@ export class ImageKnife {
|
||||||
displayProgress: displayProgress,
|
displayProgress: displayProgress,
|
||||||
uuid: request.uuid,
|
uuid: request.uuid,
|
||||||
dontAnimateFlag: request.dontAnimateFlag,
|
dontAnimateFlag: request.dontAnimateFlag,
|
||||||
|
priority:request.priority,
|
||||||
generateCacheKey: request.generateCacheKey,
|
generateCacheKey: request.generateCacheKey,
|
||||||
generateResourceKey: request.generateResourceKey,
|
generateResourceKey: request.generateResourceKey,
|
||||||
generateDataKey: request.generateDataKey,
|
generateDataKey: request.generateDataKey,
|
||||||
|
@ -727,6 +728,7 @@ async function taskExecute(taskParams: TaskParams, loadSrcJson: string): Promise
|
||||||
//子线程构造RequestOption对象
|
//子线程构造RequestOption对象
|
||||||
let newRequestOption = new RequestOption();
|
let newRequestOption = new RequestOption();
|
||||||
let loadSrcObj: object = JSON.parse(loadSrcJson);
|
let loadSrcObj: object = JSON.parse(loadSrcJson);
|
||||||
|
newRequestOption.priority = taskParams.priority
|
||||||
newRequestOption.uuid = taskParams.uuid;
|
newRequestOption.uuid = taskParams.uuid;
|
||||||
newRequestOption.loadSrc = loadSrcObj["loadSrc"] as string | PixelMap | Resource;
|
newRequestOption.loadSrc = loadSrcObj["loadSrc"] as string | PixelMap | Resource;
|
||||||
newRequestOption.dontAnimateFlag = taskParams.dontAnimateFlag;
|
newRequestOption.dontAnimateFlag = taskParams.dontAnimateFlag;
|
||||||
|
|
|
@ -251,6 +251,9 @@ export struct ImageKnifeComponent {
|
||||||
request.signature = new ObjectKey(new Date().getTime().toString())
|
request.signature = new ObjectKey(new Date().getTime().toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( this.imageKnifeOption.priority != undefined) {
|
||||||
|
request.setPriority(this.imageKnifeOption.priority)
|
||||||
|
}
|
||||||
if (this.imageKnifeOption.placeholderSrc) {
|
if (this.imageKnifeOption.placeholderSrc) {
|
||||||
request.placeholder(this.imageKnifeOption.placeholderSrc, {asyncSuccess:(data:ImageKnifeData) => {
|
request.placeholder(this.imageKnifeOption.placeholderSrc, {asyncSuccess:(data:ImageKnifeData) => {
|
||||||
LogUtil.log('ImageKnife ImageKnifeComponent request.placeholder callback')
|
LogUtil.log('ImageKnife ImageKnifeComponent request.placeholder callback')
|
||||||
|
|
|
@ -26,6 +26,7 @@ import { rgbColor } from './transform/CropCircleWithBorderTransformation'
|
||||||
import { RoundCorner } from './transform/RoundedCornersTransformation'
|
import { RoundCorner } from './transform/RoundedCornersTransformation'
|
||||||
import { ObjectKey } from './ObjectKey'
|
import { ObjectKey } from './ObjectKey'
|
||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common'
|
||||||
|
import { Priority } from './RequestOption'
|
||||||
|
|
||||||
export interface CropCircleWithBorder{
|
export interface CropCircleWithBorder{
|
||||||
border: number,
|
border: number,
|
||||||
|
@ -72,7 +73,8 @@ export class ImageKnifeOption {
|
||||||
// 主图资源
|
// 主图资源
|
||||||
loadSrc: string | PixelMap | Resource = '';
|
loadSrc: string | PixelMap | Resource = '';
|
||||||
mainScaleType?: ScaleType = ScaleType.FIT_CENTER
|
mainScaleType?: ScaleType = ScaleType.FIT_CENTER
|
||||||
|
// 优先级
|
||||||
|
priority?: Priority = Priority.MEDIUM
|
||||||
enableGpu?:boolean = true;
|
enableGpu?:boolean = true;
|
||||||
|
|
||||||
// 磁盘缓存策略
|
// 磁盘缓存策略
|
||||||
|
|
|
@ -68,7 +68,11 @@ export interface Size {
|
||||||
export interface DetachFromLayout {
|
export interface DetachFromLayout {
|
||||||
detach: () => void
|
detach: () => void
|
||||||
}
|
}
|
||||||
|
export enum Priority {
|
||||||
|
HIGH = 0,
|
||||||
|
MEDIUM = 1,
|
||||||
|
LOW = 2
|
||||||
|
}
|
||||||
export class RequestOption {
|
export class RequestOption {
|
||||||
// 遍历添加图片http请求头
|
// 遍历添加图片http请求头
|
||||||
headers: Map<string, Object> = new Map<string, Object>();
|
headers: Map<string, Object> = new Map<string, Object>();
|
||||||
|
@ -82,7 +86,8 @@ export class RequestOption {
|
||||||
addHeaderMap(map: Map<string, Object>) {
|
addHeaderMap(map: Map<string, Object>) {
|
||||||
this.headers = map;
|
this.headers = map;
|
||||||
}
|
}
|
||||||
|
// 优先级
|
||||||
|
priority: Priority = Priority.MEDIUM;
|
||||||
uuid: string = '' // 唯一标识
|
uuid: string = '' // 唯一标识
|
||||||
loadSrc: string | PixelMap | Resource = '';
|
loadSrc: string | PixelMap | Resource = '';
|
||||||
strategy: DiskStrategy = new AUTOMATIC();
|
strategy: DiskStrategy = new AUTOMATIC();
|
||||||
|
@ -158,7 +163,9 @@ export class RequestOption {
|
||||||
this.moduleContext = ctx;
|
this.moduleContext = ctx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setPriority(priority: Priority) {
|
||||||
|
this.priority = priority
|
||||||
|
}
|
||||||
generateUUID(): string {
|
generateUUID(): string {
|
||||||
let d = new Date().getTime();
|
let d = new Date().getTime();
|
||||||
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(new RegExp("[xy]", "g"), (c) => {
|
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(new RegExp("[xy]", "g"), (c) => {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { ObjectKey } from './ObjectKey';
|
import { ObjectKey } from './ObjectKey';
|
||||||
import { Size } from '../imageknife/RequestOption'
|
import { Priority, Size } from '../imageknife/RequestOption'
|
||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common'
|
||||||
|
|
||||||
export class TaskParams {
|
export class TaskParams {
|
||||||
|
@ -22,6 +22,7 @@ export class TaskParams {
|
||||||
transformations: string [][] = []
|
transformations: string [][] = []
|
||||||
usageType: string = ''
|
usageType: string = ''
|
||||||
displayProgress: boolean = false
|
displayProgress: boolean = false
|
||||||
|
priority: Priority = Priority.MEDIUM // 优先级
|
||||||
uuid: string = '' // 唯一标识
|
uuid: string = '' // 唯一标识
|
||||||
dontAnimateFlag: boolean = false;
|
dontAnimateFlag: boolean = false;
|
||||||
thumbSizeMultiplier: number = 0;
|
thumbSizeMultiplier: number = 0;
|
||||||
|
|
|
@ -99,7 +99,7 @@ export { ImageKnife } from '@ohos/imageknife'
|
||||||
export { ImageKnifeGlobal } from '@ohos/imageknife'
|
export { ImageKnifeGlobal } from '@ohos/imageknife'
|
||||||
export {RequestOption,Size} from '@ohos/imageknife'
|
export {RequestOption,Size} from '@ohos/imageknife'
|
||||||
export {ObjectKey} from '@ohos/imageknife'
|
export {ObjectKey} from '@ohos/imageknife'
|
||||||
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing} from '@ohos/imageknife'
|
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper, AntiAliasing, Priority} from '@ohos/imageknife'
|
||||||
export { ImageKnifeDrawFactory } from '@ohos/imageknife'
|
export { ImageKnifeDrawFactory } from '@ohos/imageknife'
|
||||||
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from '@ohos/imageknife'
|
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions,HeaderOptions} from '@ohos/imageknife'
|
||||||
export { ImageKnifeData } from '@ohos/imageknife'
|
export { ImageKnifeData } from '@ohos/imageknife'
|
||||||
|
|
Loading…
Reference in New Issue