Compare commits

...

6 Commits

Author SHA1 Message Date
tyBrave 75afa35e5b
Pre Merge pull request !414 from tyBrave/3.x 2024-10-29 08:42:40 +00:00
tyBrave 1153390393 保持英文README不变
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-29 16:42:32 +08:00
tyBrave 7210d5060b 更新README文件
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-29 16:23:38 +08:00
tyBrave 1c7bedc6d5 同步3.x分支代码
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-29 07:31:35 +00:00
tyBrave 5f2e80400a 更改针对接口回调信息需求的审核意见
Signed-off-by: tyBrave <tianyong21@h-partners.com>
2024-10-29 15:17:47 +08:00
zgf fd0394a80a 排队队列改为Queue、showPixelMap回调改为同步
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-10-28 14:39:40 +08:00
13 changed files with 37 additions and 58 deletions

View File

@ -1,6 +1,8 @@
## 3.2.0-rc.1
- Added callback information for image loading
- Added the interface for obtaining the upper limit and size of the current cache and the number of images corresponding to the current cache
- Change the queue from Stack to Queue
- ShowPixelMap callback PixelMap assigns value to Image component to synchronize
## 3.2.0-rc.0
- Rollback the old version V1 decorator. V2 decorator will be provided in version 4.x

View File

@ -264,36 +264,6 @@ ImageKnifeAnimatorComponent({
},animatorOption:this.animatorOption
}).width(300).height(300).backgroundColor(Color.Orange).margin({top:30})
```
#### 11.Load the image callback information data
```
ImageKnifeComponent({ ImageKnifeOption: = new ImageKnifeOption({
loadSrc: $r('app.media.pngSample'),
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: (req) => {
let startCallBackData = JSON.stringify(req?.getImageKnifeData());
},
onLoadFailed: (res, req) => {
let failedBackData = res + ";" + JSON.stringify(req?.getImageKnifeData());
},
onLoadSuccess: (data, imageData, req) => {
let successBackData = JSON.stringify(req?.getImageKnifeData());
},
onLoadCancel: (res, req) => {
let cancelBackData = res + ";" + JSON.stringify(req?.getImageKnifeData());
}
},
border: { radius: 50 },
onComplete: (event) => {
if (event && event.loadingStatus == 0) {
let render_success = JSON.stringify(Date.now())
}
}
})
}).width(100).height(100)
```
#### Reuse Scenario
Clear the component content in the **aboutToRecycle** lifecycle and trigger image loading through watch observeration.
## Available APIs
@ -337,7 +307,7 @@ Clear the component content in the **aboutToRecycle** lifecycle and trigger imag
| transformation | PixelMapTransformation | Image transformation. Optional. |
| drawingColorFilter | ColorFilter | Drawing color filter. Optional. |
| onComplete | (event:EventImage \| undefined)=>void | Callback for image loading completion. Optional. |
| onLoadListener | onLoadStart?: (req?: ImageKnifeRequest) => void,onLoadSuccess?: (data: string \| PixelMap \| undefined, imageData: ImageKnifeData, req?: ImageKnifeRequest) => void,onLoadFailed?: (err: string, req?: ImageKnifeRequest) => void,onLoadCancel?: (res: string, req?: ImageKnifeRequest) => void | Callback for image loading events. Optional. |
| onLoadListener | onLoadStart:()=>void,onLoadSuccess:(data:string\|Pixelmap)=>void | Callback for image loading events. Optional. |
### ImageKnife
@ -355,10 +325,6 @@ Clear the component content in the **aboutToRecycle** lifecycle and trigger imag
| putCacheImage | url: string, pixelMap: PixelMap, cacheType: CacheStrategy = CacheStrategy.Default, signature?: string | Writes to the memory disk cache. |
| removeMemoryCache | url: string | Removes an entry from the memory cache. |
| removeFileCache | url: string | Removes an entry from the file cache. |
| getCacheLimitSize | cacheType?: CacheStrategy | Gets the upper limit size of the specified cache |
| getCurrentCacheNum | cacheType?: CacheStrategy | Gets the number of images currently cached in the specified cache |
| getCurrentCacheSize | cacheType?: CacheStrategy | Gets the current size of the specified cache |
### Graphics tRansformation Types (GPUImage Dependency Required)
| Type | Description |
@ -406,4 +372,4 @@ This project is licensed under [Apache License 2.0](https://gitee.com/openharmon
## Known Issues
- The **ImageFit** attribute cannot be set for the **ImageKnifeAnimator** component.
- The **border** attribute of the **ImageKnifeAnimator** component cannot make the image rounded corners.
- The **border** attribute of the **ImageKnifeAnimator** component cannot make the image rounded corners.

View File

@ -264,6 +264,7 @@ ImageKnifeAnimatorComponent({
},animatorOption:this.animatorOption
}).width(300).height(300).backgroundColor(Color.Orange).margin({top:30})
```
#### 11.加载图片回调信息数据 示例
```
ImageKnifeComponent({ ImageKnifeOption: = new ImageKnifeOption({
@ -293,6 +294,7 @@ ImageKnifeComponent({ ImageKnifeOption: = new ImageKnifeOption({
}).width(100).height(100)
```
#### 复用场景
在aboutToRecycle生命周期清空组件内容通过watch监听触发图片的加载。
## 接口说明
@ -360,7 +362,15 @@ ImageKnifeComponent({ ImageKnifeOption: = new ImageKnifeOption({
| getCacheLimitSize | cacheType?: CacheStrategy | 获取指定缓存的上限大小 |
| getCurrentCacheNum | cacheType?: CacheStrategy | 获取指定缓存的当前缓存图片个数 |
| getCurrentCacheSize | cacheType?: CacheStrategy | 获取指定缓存的当前大小 |
| getCurrentCacheSize | cacheType?: CacheStrategy | 获取指定缓存的当前大小 |
### 回调接口说明
| 回调接口 | 回调字段 | 回调描述 |
|----------------|-------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| onLoadStart | req: ImageKnifeRequest | req返回字段中包含了图片请求的信息如图片的url及其组件的宽高同时ImageKnifeRequest包含了ImageKnifeData其中包含此次请求的开始及其检查内存缓存的时间点 |
| onLoadSuccess | data: string \| PixelMap \| undefined, imageData: ImageKnifeData, req?: ImageKnifeRequest | data:加载成功的结果数据imageData图片的存入缓存中的信息 req图片请求的信息同时其中的ImageKnifeData包含此次请求中图片的原始大小、图片的解码大小、格式、图片帧、请求结束时间、磁盘检查时间、网络请求开始结束、图片解码开始结束等时间点 |
| onLoadFailed | err: string, req?: ImageKnifeRequest | err:错误信息描述req图片请求的信息同时其中的ImageKnifeData包含此次请求错误信息ErrorInfoTimeInfoErrorInfo其中包含了错误阶段、错误码及其网络请求的错误码TimeInfo中包含请求结束时间、磁盘检查时间、网络请求开始结束、图片解码开始结束等时间点 |
| onLoadCancel | reason: string, req?: ImageKnifeRequest | reason:取消回调原因req图片请求的信息同时其中的ImageKnifeData包含此次请求错误信息ErrorInfoTimeInfoErrorInfo其中包含了错误阶段、错误码及其网络请求的错误码TimeInfo中包含请求结束时间、磁盘检查时间、网络请求开始结束、图片解码开始结束及其请求取消等时间点 |
### 图形变换类型需要为GPUImage添加依赖项

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { ImageKnife, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
import { ImageKnife, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry
@Component

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { ImageKnifeComponent, ImageKnifeData, ImageKnifeOption, ImageKnifeRequest } from '@ohos/imageknife';
import { ImageKnifeComponent, ImageKnifeData, ImageKnifeOption, ImageKnifeRequest } from '@ohos/libraryimageknife';
import { router } from '@kit.ArkUI';
@Entry

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { ImageKnifeComponent} from '@ohos/imageknife';
import { ImageKnifeComponent} from '@ohos/libraryimageknife';
class ArrayElement {
src: string = "";

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry

View File

@ -55,12 +55,12 @@ export default function DefaultJobQueueTest() {
expect(job.getQueueLength()).assertEqual(7)
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("high1")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium1")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low1")
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
expect(job.pop()).assertEqual(undefined)
expect(job.getQueueLength()).assertEqual(0)

View File

@ -84,7 +84,8 @@ export class ImageKnifeDispatcher {
LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadStart:" + request.imageKnifeOption.loadSrc)
}
LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.start:" + request.imageKnifeOption.loadSrc)
request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source, requestSource,memoryCache.imageAnimator)
request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source,
{ width: memoryCache.imageWidth, height: memoryCache.imageHeight }, requestSource, memoryCache.imageAnimator)
LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.end:" + request.imageKnifeOption.loadSrc)
if (requestSource == ImageKnifeRequestSource.SRC) {
@ -425,7 +426,8 @@ export class ImageKnifeDispatcher {
requestWithSource.request.requestState === ImageKnifeRequestState.PROGRESS)) {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.start:"+currentRequest.imageKnifeOption.loadSrc)
requestWithSource.request.ImageKnifeRequestCallback.showPixelMap(requestWithSource.request.componentVersion,
imageKnifeData.source, requestWithSource.source,imageKnifeData.imageAnimator);
imageKnifeData.source, { width: imageKnifeData.imageWidth, height: imageKnifeData.imageHeight },
requestWithSource.source, imageKnifeData.imageAnimator);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.end:"+currentRequest.imageKnifeOption.loadSrc)
}
@ -436,7 +438,7 @@ export class ImageKnifeDispatcher {
// 回调请求成功
this.assembleImageKnifeData(requestWithSource.request.getImageKnifeData(), imageKnifeData,requestWithSource.request);
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(imageKnifeData.source,
imageKnifeData, requestWithSource.request);
saveCacheImageData, requestWithSource.request);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc)
}
} else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) {

View File

@ -111,7 +111,7 @@ export struct ImageKnifeAnimatorComponent {
height,
this.componentVersion,
{
showPixelMap: async (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => {
showPixelMap: (version: number, pixelMap: PixelMap | string,size: Size, requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => {
if (version !== this.componentVersion) {
return //针对reuse场景不显示历史图片
}

View File

@ -134,17 +134,16 @@ export struct ImageKnifeComponent {
height,
this.componentVersion,
{
showPixelMap: async (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource) => {
showPixelMap: (version: number, pixelMap: PixelMap | string,size:Size, requestSource: ImageKnifeRequestSource) => {
if (version !== this.componentVersion) {
return //针对reuse场景不显示历史图片
}
this.pixelMap = pixelMap
if (typeof this.pixelMap !== 'string') {
if (this.imageKnifeOption.objectFit === ImageFit.Auto) {
let info = await this.pixelMap.getImageInfo()
this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
this.adaptiveHeight = size.height * this.currentWidth / size.width
// if (this.currentWidth / this.currentHeight > info.size.width / info.size.height) {
// this.adaptiveWidth = this.currentWidth

View File

@ -73,5 +73,5 @@ export enum ImageKnifeRequestState {
export interface ImageKnifeRequestCallback {
showPixelMap: (version: number, pixelMap: PixelMap | string , requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => void;
showPixelMap: (version: number, pixelMap: PixelMap | string ,size: Size, requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => void;
}

View File

@ -18,9 +18,9 @@ import Queue from '@ohos.util.Queue';
import { taskpool,Stack } from '@kit.ArkTS';
export class DefaultJobQueue implements IJobQueue {
highQueue: Stack<ImageKnifeRequest> = new Stack();
normalQueue: Stack<ImageKnifeRequest> = new Stack();
lowQueue: Stack<ImageKnifeRequest> = new Stack();
highQueue: Queue<ImageKnifeRequest> = new Queue();
normalQueue: Queue<ImageKnifeRequest> = new Queue();
lowQueue: Queue<ImageKnifeRequest> = new Queue();
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.push(request)
this.normalQueue.add(request)
} else if (request.imageKnifeOption.priority === taskpool.Priority.HIGH) {
this.highQueue.push(request)
this.highQueue.add(request)
} else {
this.lowQueue.push(request)
this.lowQueue.add(request)
}
}