mirror of
https://gitee.com/openharmony-tpc/ImageKnife.git
synced 2026-07-16 22:48:44 +08:00
文件缓存初始化增加默认值、预加载接口新增返回加载错误信息、加载队列从队列从Queue改为Stack以及fileType新增heic格式
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
@@ -53,7 +53,7 @@ export class ImageKnife {
|
||||
* @param size 缓存数量
|
||||
* @param memory 内存大小
|
||||
*/
|
||||
async initFileCache(context: Context, size: number, memory: number) {
|
||||
async initFileCache(context: Context, size: number = 256, memory: number = 256 * 1024 * 1024) {
|
||||
this.fileCache = new FileCache(context, size, memory)
|
||||
await this.fileCache.initFileCache()
|
||||
}
|
||||
@@ -163,6 +163,14 @@ export class ImageKnife {
|
||||
let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature)
|
||||
let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey)
|
||||
if (cachePath == null || cachePath == "" || cachePath == undefined) {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadSuccess(){
|
||||
resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey))
|
||||
},
|
||||
onLoadFailed(err) {
|
||||
reject(err)
|
||||
}
|
||||
}
|
||||
let request = new ImageKnifeRequest(
|
||||
imageKnifeOption,
|
||||
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext(this) as common.UIAbilityContext,
|
||||
@@ -171,7 +179,6 @@ export class ImageKnife {
|
||||
0,
|
||||
{
|
||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||
resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
import { ImageKnifeRequest } from '../ImageKnifeRequest';
|
||||
import { IJobQueue } from './IJobQueue'
|
||||
import Queue from '@ohos.util.Queue';
|
||||
import { taskpool } from '@kit.ArkTS';
|
||||
import { taskpool,Stack } from '@kit.ArkTS';
|
||||
|
||||
export class DefaultJobQueue implements IJobQueue {
|
||||
highQueue: Queue<ImageKnifeRequest> = new Queue();
|
||||
normalQueue: Queue<ImageKnifeRequest> = new Queue();
|
||||
lowQueue: Queue<ImageKnifeRequest> = new Queue();
|
||||
highQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||
normalQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||
lowQueue: Stack<ImageKnifeRequest> = new Stack();
|
||||
|
||||
getQueueLength(): number {
|
||||
return this.highQueue.length + this.normalQueue.length + this.lowQueue.length
|
||||
@@ -28,11 +28,11 @@ export class DefaultJobQueue implements IJobQueue {
|
||||
|
||||
add(request: ImageKnifeRequest): void {
|
||||
if (request.imageKnifeOption.priority === undefined || request.imageKnifeOption.priority === taskpool.Priority.MEDIUM) {
|
||||
this.normalQueue.add(request)
|
||||
this.normalQueue.push(request)
|
||||
} else if (request.imageKnifeOption.priority === taskpool.Priority.HIGH) {
|
||||
this.highQueue.add(request)
|
||||
this.highQueue.push(request)
|
||||
} else {
|
||||
this.lowQueue.add(request)
|
||||
this.lowQueue.push(request)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export class FileTypeUtil {
|
||||
'webp': [new Uint8Array([0x52, 0x49, 0x46, 0x46])],
|
||||
'tiff': [new Uint8Array([0x49, 0x20, 0x49]), new Uint8Array([0x49, 0x49, 0x2A, 0x00]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2A]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2B])],
|
||||
// 添加更多的文件类型和特征
|
||||
'heic': [new Uint8Array([0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63, 0x00, 0x00, 0x00, 0x00])],
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +41,8 @@ export class FileTypeUtil {
|
||||
value == SupportFormat.webp ||
|
||||
value == SupportFormat.bmp ||
|
||||
value == SupportFormat.gif ||
|
||||
value == SupportFormat.svg
|
||||
value == SupportFormat.svg ||
|
||||
value == SupportFormat.heic
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -105,5 +107,6 @@ export enum SupportFormat {
|
||||
bmp = 'bmp',
|
||||
gif = 'gif',
|
||||
svg = 'svg',
|
||||
tiff = 'tiff'
|
||||
tiff = 'tiff',
|
||||
heic = 'heic'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user