Pre Merge pull request !315 from zgf/3.x
This commit is contained in:
commit
c7789f082a
|
@ -1,3 +1,9 @@
|
||||||
|
## 3.0.0-rc.9
|
||||||
|
- 修复Resource类型$r(变量无法)加载
|
||||||
|
- 成功回调增加图片格式
|
||||||
|
- Image组件增加onComplete回调
|
||||||
|
- 修复404链接无返回错误信息
|
||||||
|
|
||||||
## 3.0.0-rc.8
|
## 3.0.0-rc.8
|
||||||
- svg解码单位改为px
|
- svg解码单位改为px
|
||||||
- 修复预加载接口preLoadCache传ImageKnifeOption失效
|
- 修复预加载接口preLoadCache传ImageKnifeOption失效
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct LoadStatePage {
|
||||||
}
|
}
|
||||||
@State currentWidth: number = 200
|
@State currentWidth: number = 200
|
||||||
@State currentHeight: number = 200
|
@State currentHeight: number = 200
|
||||||
|
@State typeValue: string = ""
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
Text('测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存')
|
Text('测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存')
|
||||||
|
@ -58,10 +59,11 @@ struct LoadStatePage {
|
||||||
onLoadFailed: (err) => {
|
onLoadFailed: (err) => {
|
||||||
console.error("Load Failed Reason: " + err + " cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
console.error("Load Failed Reason: " + err + " cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
||||||
},
|
},
|
||||||
onLoadSuccess: (data,width,height) => {
|
onLoadSuccess: (data,imageData) => {
|
||||||
console.info("Load Successful: cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
console.info("Load Successful: cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
||||||
this.currentWidth = width!
|
this.currentWidth = imageData.imageWidth!
|
||||||
this.currentHeight = height!
|
this.currentHeight = imageData.imageHeight!
|
||||||
|
this.typeValue = imageData.type
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -70,7 +72,7 @@ struct LoadStatePage {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.margin({ top: 20 })
|
.margin({ top: 20 })
|
||||||
|
Text(this.typeValue)
|
||||||
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth)
|
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth)
|
||||||
.margin({ top: 20 })
|
.margin({ top: 20 })
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"main": "index.ets",
|
"main": "index.ets",
|
||||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "3.0.0-rc.8",
|
"version": "3.0.0-rc.9",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ohos/gpu_transform": "^1.0.2"
|
"@ohos/gpu_transform": "^1.0.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -82,7 +82,7 @@ export class ImageKnifeDispatcher {
|
||||||
request.requestState = ImageKnifeRequestState.COMPLETE
|
request.requestState = ImageKnifeRequestState.COMPLETE
|
||||||
// 回调请求开结束
|
// 回调请求开结束
|
||||||
if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) {
|
if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) {
|
||||||
request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source,memoryCache.imageWidth,memoryCache.imageHeight)
|
request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source,memoryCache)
|
||||||
LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadSuccess:" + request.imageKnifeOption.loadSrc)
|
LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadSuccess:" + request.imageKnifeOption.loadSrc)
|
||||||
}
|
}
|
||||||
} else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) {
|
} else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) {
|
||||||
|
@ -272,7 +272,8 @@ export class ImageKnifeDispatcher {
|
||||||
let ImageKnifeData: ImageKnifeData = {
|
let ImageKnifeData: ImageKnifeData = {
|
||||||
source: pixelmap!,
|
source: pixelmap!,
|
||||||
imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width,
|
imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width,
|
||||||
imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height
|
imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height,
|
||||||
|
type:requestJobResult.type
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保存内存缓存
|
// 保存内存缓存
|
||||||
|
@ -305,7 +306,7 @@ export class ImageKnifeDispatcher {
|
||||||
if (requestWithSource.request.imageKnifeOption.onLoadListener &&
|
if (requestWithSource.request.imageKnifeOption.onLoadListener &&
|
||||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess) {
|
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess) {
|
||||||
// 回调请求成功
|
// 回调请求成功
|
||||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData.imageWidth,ImageKnifeData.imageHeight);
|
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData);
|
||||||
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc)
|
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc)
|
||||||
}
|
}
|
||||||
} else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) {
|
} else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) {
|
||||||
|
@ -447,6 +448,8 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
await promise.then((data: number) => {
|
await promise.then((data: number) => {
|
||||||
if (data == 200) {
|
if (data == 200) {
|
||||||
resBuf = combineArrayBuffers(arrayBuffers)
|
resBuf = combineArrayBuffers(arrayBuffers)
|
||||||
|
} else {
|
||||||
|
loadError = "HttpDownloadClient has error, http code =" + JSON.stringify(data)
|
||||||
}
|
}
|
||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
loadError = err.message;
|
loadError = err.message;
|
||||||
|
@ -501,16 +504,21 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
}
|
}
|
||||||
} else if ((request.src as Resource).id !== undefined) { //从资源文件获取
|
} else if ((request.src as Resource).id !== undefined) { //从资源文件获取
|
||||||
let res = request.src as Resource;
|
let res = request.src as Resource;
|
||||||
|
let manager = request.context.createModuleContext(res.moduleName).resourceManager
|
||||||
if (resBuf == undefined && request.onlyRetrieveFromCache != true && request.requestSource == ImageKnifeRequestSource.SRC) {
|
if (resBuf == undefined && request.onlyRetrieveFromCache != true && request.requestSource == ImageKnifeRequestSource.SRC) {
|
||||||
resBuf = request.context.createModuleContext(res.moduleName)
|
if(res.id == -1) {
|
||||||
.resourceManager
|
let resName = (res.params![0] as string)
|
||||||
.getMediaContentSync(res.id)
|
resBuf = (await manager.getMediaByName(resName.substring(10))).buffer as ArrayBuffer
|
||||||
.buffer as ArrayBuffer;
|
} else {
|
||||||
|
resBuf = manager.getMediaContentSync(res.id).buffer as ArrayBuffer
|
||||||
|
}
|
||||||
} else if (resBuf == undefined && request.requestSource != ImageKnifeRequestSource.SRC) {
|
} else if (resBuf == undefined && request.requestSource != ImageKnifeRequestSource.SRC) {
|
||||||
resBuf = request.context.createModuleContext(res.moduleName)
|
if(res.id == -1) {
|
||||||
.resourceManager
|
let resName = (res.params![0] as string)
|
||||||
.getMediaContentSync(res.id)
|
resBuf = (await manager.getMediaByName(resName.substring(10))).buffer as ArrayBuffer
|
||||||
.buffer as ArrayBuffer;
|
} else {
|
||||||
|
resBuf = manager.getMediaContentSync(res.id).buffer as ArrayBuffer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,6 +536,14 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
LogUtil.log("ImageKnife_DataTime_requestJob_createPixelMap.start:"+request.src)
|
LogUtil.log("ImageKnife_DataTime_requestJob_createPixelMap.start:"+request.src)
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(resBuf);
|
let typeValue = fileTypeUtil.getFileType(resBuf);
|
||||||
|
if(typeValue == null) {
|
||||||
|
return {
|
||||||
|
pixelMap: undefined,
|
||||||
|
bufferSize: 0,
|
||||||
|
fileKey: '',
|
||||||
|
loadFail: "getFileType is null",
|
||||||
|
}
|
||||||
|
}
|
||||||
let imageSource: image.ImageSource = image.createImageSource(resBuf);
|
let imageSource: image.ImageSource = image.createImageSource(resBuf);
|
||||||
let decodingOptions: image.DecodingOptions = {
|
let decodingOptions: image.DecodingOptions = {
|
||||||
editable: true,
|
editable: true,
|
||||||
|
@ -545,7 +561,8 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
pixelMap: base64str,
|
pixelMap: base64str,
|
||||||
bufferSize: bufferSize,
|
bufferSize: bufferSize,
|
||||||
fileKey: fileKey,
|
fileKey: fileKey,
|
||||||
size:size
|
size:size,
|
||||||
|
type:typeValue
|
||||||
};
|
};
|
||||||
} else if(typeValue == "svg") {
|
} else if(typeValue == "svg") {
|
||||||
let hValue = Math.round(request.componentHeight);
|
let hValue = Math.round(request.componentHeight);
|
||||||
|
@ -567,6 +584,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
pixelMap: resPixelmap,
|
pixelMap: resPixelmap,
|
||||||
bufferSize: bufferSize,
|
bufferSize: bufferSize,
|
||||||
fileKey: fileKey,
|
fileKey: fileKey,
|
||||||
|
type:typeValue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let size = (await imageSource.getImageInfo()).size
|
let size = (await imageSource.getImageInfo()).size
|
||||||
|
@ -586,7 +604,8 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
||||||
pixelMap: resPixelmap,
|
pixelMap: resPixelmap,
|
||||||
bufferSize: bufferSize,
|
bufferSize: bufferSize,
|
||||||
fileKey: fileKey,
|
fileKey: fileKey,
|
||||||
size:size
|
size:size,
|
||||||
|
type:typeValue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,26 @@
|
||||||
*/
|
*/
|
||||||
import taskpool from '@ohos.taskpool';
|
import taskpool from '@ohos.taskpool';
|
||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common'
|
||||||
import { CacheStrategy } from './model/ImageKnifeData';
|
import { CacheStrategy, ImageKnifeData } from './model/ImageKnifeData';
|
||||||
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
||||||
|
|
||||||
export interface HeaderOptions {
|
export interface HeaderOptions {
|
||||||
key: string;
|
key: string;
|
||||||
value: Object;
|
value: Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EventImage {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
componentWidth: number;
|
||||||
|
componentHeight: number;
|
||||||
|
loadingStatus: number;
|
||||||
|
contentWidth: number;
|
||||||
|
contentHeight: number;
|
||||||
|
contentOffsetX: number;
|
||||||
|
contentOffsetY: number;
|
||||||
|
}
|
||||||
|
|
||||||
@Observed
|
@Observed
|
||||||
export class ImageKnifeOption {
|
export class ImageKnifeOption {
|
||||||
// 主图资源
|
// 主图资源
|
||||||
|
@ -29,37 +42,27 @@ export class ImageKnifeOption {
|
||||||
placeholderSrc?: string | PixelMap | Resource;
|
placeholderSrc?: string | PixelMap | Resource;
|
||||||
// 失败占位图
|
// 失败占位图
|
||||||
errorholderSrc?: string | PixelMap | Resource;
|
errorholderSrc?: string | PixelMap | Resource;
|
||||||
|
|
||||||
headerOption?: Array<HeaderOptions>;
|
headerOption?: Array<HeaderOptions>;
|
||||||
|
|
||||||
// 自定义缓存关键字
|
// 自定义缓存关键字
|
||||||
signature?: string;
|
signature?: string;
|
||||||
|
|
||||||
// 主图填充效果
|
// 主图填充效果
|
||||||
objectFit?: ImageFit
|
objectFit?: ImageFit
|
||||||
|
|
||||||
// 占位图填充效果
|
// 占位图填充效果
|
||||||
placeholderObjectFit?: ImageFit
|
placeholderObjectFit?: ImageFit
|
||||||
|
|
||||||
// 错误图填充效果
|
// 错误图填充效果
|
||||||
errorholderObjectFit?: ImageFit
|
errorholderObjectFit?: ImageFit
|
||||||
|
|
||||||
customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise<ArrayBuffer | undefined>
|
customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise<ArrayBuffer | undefined>
|
||||||
|
|
||||||
border?: BorderOptions
|
border?: BorderOptions
|
||||||
// 缓存策略
|
// 缓存策略
|
||||||
writeCacheStrategy?: CacheStrategy
|
writeCacheStrategy?: CacheStrategy
|
||||||
// 仅使用缓存加载数据
|
// 仅使用缓存加载数据
|
||||||
onlyRetrieveFromCache?: boolean = false;
|
onlyRetrieveFromCache?: boolean = false;
|
||||||
|
priority?: taskpool.Priority = taskpool.Priority.LOW
|
||||||
priority? : taskpool.Priority = taskpool.Priority.LOW
|
|
||||||
|
|
||||||
context?: common.UIAbilityContext;
|
context?: common.UIAbilityContext;
|
||||||
|
progressListener?: (progress: number) => void;
|
||||||
progressListener?: (progress: number)=>void;
|
|
||||||
|
|
||||||
transformation?: PixelMapTransformation
|
transformation?: PixelMapTransformation
|
||||||
onLoadListener?: OnLoadCallBack | undefined;
|
onLoadListener?: OnLoadCallBack | undefined;
|
||||||
|
omComplete?: (event:EventImage| undefined) => void
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
|
@ -72,8 +75,10 @@ export class ImageKnifeOption {
|
||||||
export interface OnLoadCallBack {
|
export interface OnLoadCallBack {
|
||||||
// 请求开始
|
// 请求开始
|
||||||
onLoadStart?: () => void;
|
onLoadStart?: () => void;
|
||||||
|
|
||||||
// 请求成功
|
// 请求成功
|
||||||
onLoadSuccess?: (data: string | PixelMap | undefined,width?:number,height?:number) => void;
|
onLoadSuccess?: (data: string | PixelMap | undefined, ImageKnifeData:ImageKnifeData) => void;
|
||||||
|
|
||||||
// 请求结束
|
// 请求结束
|
||||||
onLoadFailed?: (err: string) => void;
|
onLoadFailed?: (err: string) => void;
|
||||||
}
|
}
|
|
@ -83,6 +83,7 @@ export struct ImageKnifeComponent {
|
||||||
.border(this.imageKnifeOption.border)
|
.border(this.imageKnifeOption.border)
|
||||||
.syncLoad(this.syncLoad)
|
.syncLoad(this.syncLoad)
|
||||||
.draggable(false)
|
.draggable(false)
|
||||||
|
.onComplete(this.imageKnifeOption.omComplete)
|
||||||
.onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => {
|
.onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => {
|
||||||
this.currentWidth = newValue.width as number
|
this.currentWidth = newValue.width as number
|
||||||
this.currentHeight = newValue.height as number
|
this.currentHeight = newValue.height as number
|
||||||
|
|
|
@ -22,7 +22,8 @@ import { Size } from '@kit.ArkUI'
|
||||||
export interface ImageKnifeData {
|
export interface ImageKnifeData {
|
||||||
source: PixelMap | string,
|
source: PixelMap | string,
|
||||||
imageWidth: number,
|
imageWidth: number,
|
||||||
imageHeight: number
|
imageHeight: number,
|
||||||
|
type?:string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +61,8 @@ export interface RequestJobResult {
|
||||||
bufferSize: number
|
bufferSize: number
|
||||||
fileKey: string
|
fileKey: string
|
||||||
loadFail?: string,
|
loadFail?: string,
|
||||||
size?:Size
|
size?:Size,
|
||||||
|
type?:string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue