3.x分支代码合并到master分支

Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
zgf 2024-11-06 18:58:25 +08:00
parent 0e0f1a96c2
commit 3423f4cd5d
82 changed files with 781 additions and 1021 deletions

View File

@ -304,6 +304,33 @@ ImageKnifeComponent({
}
}).width(300).height(300)
```
#### 13.rcp自定义网络请求
```
ImageKnifeComponent({
loadSrc:"http//xx.xx",
customGetImage:custom
})
// 自定义下载方法
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
return new Promise((resolve,reject)=>{
if (typeof src == "string") {
let session = GetSession.session
let req = new rcp.Request(src,"GET");
session.fetch(req).then((response)=>{
if(response.statusCode == 200) {
let buffer = response.body
resolve(buffer)
} else {
reject("rcp code:"+response.statusCode)
}
}).catch((err:BusinessError)=>{
reject("error rcp src:"+src+",err:"+JSON.stringify(err))
})
}
})
}
```
#### 复用场景
在aboutToRecycle生命周期清空组件内容通过watch监听触发图片的加载。

View File

@ -1,78 +0,0 @@
/*
* 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 { InfoItem } from './model/DataSourcePrefetching';
import { PageViewModel } from './model/PageViewModel';
import { ImageKnifeComponent, ImageKnife } from '@ohos/libraryimageknife';
import { CommonDataSource, GetSession } from './model/CommonDataSource';
import { rcp } from '@kit.RemoteCommunicationKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
export struct CustomNetImagePage {
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
aboutToAppear(): void {
ImageKnife.getInstance().setMaxRequests(32)
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
}
aboutToDisappear(): void {
ImageKnife.getInstance().setMaxRequests(8)
}
build() {
Column() {
WaterFlow() {
LazyForEach(this.hotCommendList,(item: InfoItem)=>{
FlowItem() {
Column(){
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item.albumUrl,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
customGetImage:custom
}
}).width("50%").height(200)
}
}.height(200)
.backgroundColor("#95efd2")
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
}
}
}
// 自定义下载方法
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
return new Promise((resolve,reject)=>{
if (typeof src == "string") {
let session = GetSession.session
let req = new rcp.Request(src,"GET");
session.fetch(req).then((response)=>{
if(response.statusCode == 200) {
let buffer = response.body
resolve(buffer)
} else {
reject("rcp code:"+response.statusCode)
}
}).catch((err:BusinessError)=>{
reject("error rcp src:"+src+",err:"+JSON.stringify(err))
})
}
})
}

View File

@ -24,8 +24,8 @@ import { FileTypeUtil } from '@ohos/imageknife/src/main/ets/utils/FileTypeUtil';
struct DownSamplePage {
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain
}
isBrightness: boolean = false
@ -33,14 +33,14 @@ struct DownSamplePage {
@State afterSampling: number = 0
@State SamplingList: SamplingType[] = [
new SamplingType(7, "AT_LEAST"),
new SamplingType(1, "AT_MOST"),
new SamplingType(7, 'AT_LEAST'),
new SamplingType(1, 'AT_MOST'),
new SamplingType(2, "FIT_CENTER_MEMORY"),
new SamplingType(4, "FIT_CENTER_QUALITY"),
new SamplingType(5, "CENTER_OUTSIDE_MEMORY"),
new SamplingType(6, "CENTER_OUTSIDE_QUALITY"),
new SamplingType(0, "NONE"),
new SamplingType(2, 'FIT_CENTER_MEMORY'),
new SamplingType(4, 'FIT_CENTER_QUALITY'),
new SamplingType(5, 'CENTER_OUTSIDE_MEMORY'),
new SamplingType(6, 'CENTER_OUTSIDE_QUALITY'),
new SamplingType(0, 'NONE'),
]
@State checked: boolean = false
@ -49,8 +49,8 @@ struct DownSamplePage {
if (value === 'NONE') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.NONE
}
@ -59,8 +59,8 @@ struct DownSamplePage {
} else if (value === 'AT_MOST') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.AT_MOST
}
@ -69,8 +69,8 @@ struct DownSamplePage {
} else if (value === 'FIT_CENTER_MEMORY') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.FIT_CENTER_MEMORY
}
@ -79,8 +79,8 @@ struct DownSamplePage {
} else if (value === 'FIT_CENTER_QUALITY') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.FIT_CENTER_QUALITY
}
@ -89,8 +89,8 @@ struct DownSamplePage {
} else if (value === 'CENTER_OUTSIDE_MEMORY') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_MEMORY
}
@ -99,8 +99,8 @@ struct DownSamplePage {
} else if (value === 'CENTER_OUTSIDE_QUALITY') {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_QUALITY
}
@ -109,8 +109,8 @@ struct DownSamplePage {
} else {
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
downsampleOf: DownsampleStrategy.AT_LEAST
}
@ -147,7 +147,7 @@ struct DownSamplePage {
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
this.afterSampling = pixelMap.getPixelBytesNumber()
}).catch((err: BusinessError) => {
console.error("Failed to create PixelMap")
console.error('Failed to create PixelMap')
});
}
@ -162,7 +162,7 @@ struct DownSamplePage {
imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {
this.beforeSampling = pixelMap.getPixelBytesNumber()
}).catch((err: BusinessError) => {
console.error("Failed to create PixelMap")
console.error('Failed to create PixelMap')
});
}
getResourceString(res:Resource){

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AnimatorOption, ImageKnifeAnimatorComponent } from "@ohos/libraryimageknife"
import { AnimatorOption, ImageKnifeAnimatorComponent } from '@ohos/libraryimageknife'
@Entry
@Component
@ -21,19 +21,19 @@ struct ImageAnimatorPage {
state: AnimationStatus.Running,
iterations: 1,
onFinish:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onFinish")
console.log('ImageKnifeAnimatorComponent animatorOption onFinish')
},
onStart:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onStart")
console.log('ImageKnifeAnimatorComponent animatorOption onStart')
},
onPause:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onPause")
console.log('ImageKnifeAnimatorComponent animatorOption onPause')
},
onCancel:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onCancel")
console.log('ImageKnifeAnimatorComponent animatorOption onCancel')
},
onRepeat:()=>{
console.log("ImageKnifeAnimatorComponent animatorOption onRepeat")
console.log('ImageKnifeAnimatorComponent animatorOption onRepeat')
}
}
@State animatorOption1: AnimatorOption = {
@ -67,7 +67,7 @@ struct ImageAnimatorPage {
}
ImageKnifeAnimatorComponent({
imageKnifeOption:{
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption
@ -75,7 +75,7 @@ struct ImageAnimatorPage {
Text($r('app.string.Display_the_first_frame')).fontSize(20)
ImageKnifeAnimatorComponent({
imageKnifeOption:{
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption1
@ -83,11 +83,11 @@ struct ImageAnimatorPage {
Text($r('app.string.Display_the_last_frame')).fontSize(20)
ImageKnifeAnimatorComponent({
imageKnifeOption:{
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
},animatorOption:this.animatorOption2
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
}.width("100%").height("100%")
}.width('100%').height('100%')
}
}

View File

@ -26,7 +26,7 @@ struct ImageKnifeReload {
Column() {
ImageKnifeComponent({
imageKnifeOption:{
loadSrc:"https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
loadSrc:'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'),
onLoadListener:{
@ -38,7 +38,7 @@ struct ImageKnifeReload {
}).width(200).height(200)
ImageKnifeComponent({
imageKnifeOption:{
loadSrc:"https://img-blog.csdn.net/20140514114029140",
loadSrc:'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'),
onLoadListener:{
@ -48,8 +48,8 @@ struct ImageKnifeReload {
}
}
}).width(200).height(200).margin({top:10})
}.width("100%")
.height("100%")
}.width('100%')
.height('100%')
}
}
@ -63,7 +63,7 @@ class NetWatchState {
NetWatchState.netConnection.register(()=>{
})
// 订阅网络能力变化事件。调用register后才能接收到此事件通知
NetWatchState.netConnection.on("netCapabilitiesChange",(data:connection.NetCapabilityInfo)=>{
NetWatchState.netConnection.on('netCapabilitiesChange',(data:connection.NetCapabilityInfo)=>{
if(NetWatchState.requestList.length > 0 && data.netHandle.netId >= 100) {
NetWatchState.requestList.forEach((request)=>{
ImageKnife.getInstance().reload(request)

View File

@ -35,17 +35,17 @@ import {
import { collections } from '@kit.ArkTS'
@Entry
@ComponentV2
@Component
struct ImageTransformation {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain
})
@Local isRound: boolean = false;
@Local isContrast: boolean = false;
@Local isRotate: boolean = false;
}
@State isRound: boolean = false;
@State isContrast: boolean = false;
@State isRotate: boolean = false;
isBlur: boolean = false
isBrightness: boolean = false
isGrayScale: boolean = false;
@ -412,14 +412,14 @@ struct ImageTransformation {
if (this.isMask) {
transformations.push(new MaskTransformation($r('app.media.mask_starfish')));
}
this.imageKnifeOption = new ImageKnifeOption({
this.imageKnifeOption = {
loadSrc: $r('app.media.pngSample'),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
border: { radius: this.isRound ? { topLeft: 50, bottomRight: 50 } : 0 },
transformation: transformations.length > 0 ? new MultiTransTransformation(transformations) : undefined
})
}
if (this.isCropCircle) {
this.imageKnifeOption.objectFit = ImageFit.Cover;
this.imageKnifeOption.border = { radius: 150 };

View File

@ -55,11 +55,6 @@ struct Index {
uri: 'pages/TestCommonImage',
});
})
Button($r('app.string.Customize_RCP_network')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/CustomNetImagePage',
});
})
Button($r('app.string.Test_Task_error')).margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestTaskResourcePage',
@ -83,13 +78,7 @@ struct Index {
});
})
// Button(this.getResourceString($r('app.string.Multiple_images')) + " + LazyForEach").margin({top:10}).onClick(()=>{
// router.push({
// uri: 'pages/ManyPhotoShowPage',
//
// });
// })
Button(this.getResourceString($r('app.string.Multiple_images')) + " + reuse + LazyForeach").margin({top:10}).onClick(()=>{
Button(this.getResourceString($r('app.string.Multiple_images')) + ' + reuse + LazyForeach').margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/UserPage',
@ -112,7 +101,7 @@ struct Index {
});
})
Button(this.getResourceString($r('app.string.Message_list')) + " + List").margin({top:10}).onClick(()=>{
Button(this.getResourceString($r('app.string.Message_list')) + ' + List').margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestImageFlash',

View File

@ -37,13 +37,13 @@ export struct LazyForEachCache {
}
}).width(100).height(100)
Text(`${index}`)
}.border({ width: 5 , color: "#000000"})
}.border({ width: 5 , color: '#000000'})
}
})
}
.cachedCount(5)
.width("100%")
.height("100%")
.width('100%')
.height('100%')
.margin({ left: 10, right: 10 })
.layoutWeight(1)
}

View File

@ -37,13 +37,13 @@ export struct LazyForEachCount {
}
}).width(100).height(100)
Text(`${index}`)
}.border({ width: 5 , color: "#000000"})
}.border({ width: 5 , color: '#000000'})
}
})
}
.cachedCount(30)
.width("100%")
.height("100%")
.width('100%')
.height('100%')
.margin({ left: 10, right: 10 })
.layoutWeight(1)
}

View File

@ -15,11 +15,11 @@
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry
@ComponentV2
@Component
struct ListPage {
private data: string[] = []
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({ loadSrc: $r('app.media.startIcon')})
@State ImageKnifeOption: ImageKnifeOption = { loadSrc: $r('app.media.startIcon')}
aboutToAppear(): void {

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
import matrix4 from '@ohos.matrix4'
@Entry
@ -22,13 +22,13 @@ struct LoadStatePage {
starTime:number = new Date().getTime()
@State ImageKnifeOption: ImageKnifeOption = {
loadSrc: $r("app.media.rabbit"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: $r('app.media.rabbit'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadFailed: (err) => {
console.error("Load Failed Reason: " + err);
console.error('Load Failed Reason: ' + err);
},
onLoadSuccess: (data) => {
return data;
@ -39,10 +39,10 @@ struct LoadStatePage {
@State imageKnifeOption1: ImageKnifeOption = {
loadSrc: $r('app.media.startIcon')
}
@State message: string = ""
@State message: string = ''
@State currentWidth: number = 200
@State currentHeight: number = 200
@State typeValue: string = ""
@State typeValue: string = ''
build() {
Column() {
Text($r('app.string.TIPS'))
@ -51,20 +51,20 @@ struct LoadStatePage {
Button($r('app.string.Test_failure_success'))
.onClick(() => {
this.ImageKnifeOption = {
loadSrc: "https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: 'https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png',
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart:()=>{
this.starTime = new Date().getTime()
console.info("Load start: ");
console.info('Load start: ');
},
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,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 = imageData.imageWidth!
this.currentHeight = imageData.imageHeight!
this.typeValue = imageData.type!
@ -73,7 +73,7 @@ struct LoadStatePage {
},
border: { radius: 50 },
onComplete:(event)=>{
console.error("Load onComplete width:"+event?.width , " height:"+event?.height , " componentWidth:"+event?.componentWidth," componentHeight:" + event?.componentHeight);
console.error('Load onComplete width:'+event?.width , ' height:'+event?.height , ' componentWidth:'+event?.componentWidth,' componentHeight:' + event?.componentHeight);
}
}
})
@ -86,13 +86,13 @@ struct LoadStatePage {
.margin({ top: 20 })
Button($r('app.string.Custom_download_failed')).onClick(()=>{
this.imageKnifeOption1 = {
loadSrc: "abc",
loadSrc: 'abc',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'),
customGetImage:custom,
onLoadListener: {
onLoadFailed:(err)=>{
this.message = "err:" + err
this.message = 'err:' + err
}
}
}
@ -110,7 +110,7 @@ struct LoadStatePage {
// 自定义下载方法
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
console.info("ImageKnife:: custom download" + src)
console.info('ImageKnife:: custom download' + src)
// 举例写死从本地文件读取,也可以自己请求网络图片
return undefined
}

View File

@ -12,26 +12,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
import { ImageKnifeComponent } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct LongImagePage {
build() {
Scroll() {
// Image("https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg").objectFit(ImageFit.Auto).height(300)
// Image('https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg').objectFit(ImageFit.Auto).height(300)
// Image($r("app.media.aaa")).objectFit(ImageFit.Auto).width(200)
// Image($r('app.media.aaa')).objectFit(ImageFit.Auto).width(200)
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc:"https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg",
//src:$r("app.media.aaa"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
imageKnifeOption: {
loadSrc:'https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg',
//src:$r('app.media.aaa'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Auto
})
}
})
}
.height('100%') .width('100%')

View File

@ -36,20 +36,20 @@ struct MaxRequest1 {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
}
}).width("50%").height(160)
}).width('50%').height(160)
}
}.height(200)
.backgroundColor("#95efd2")
.backgroundColor('#95efd2')
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
}.columnsTemplate('1fr 1fr')
.cachedCount(8)
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
.width('100%').height('100%')
}
}
}

View File

@ -36,20 +36,20 @@ struct MaxRequest2 {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
}
}).width("50%").height(160)
}).width('50%').height(160)
}
}.height(200)
.backgroundColor("#95efd2")
.backgroundColor('#95efd2')
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
}.columnsTemplate('1fr 1fr')
.cachedCount(20)
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
.width('100%').height('100%')
}
}
}

View File

@ -36,20 +36,20 @@ struct MaxRequest3 {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
}
}).width("50%").height(160)
}).width('50%').height(160)
}
}.height(200)
.backgroundColor("#95efd2")
.backgroundColor('#95efd2')
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
}.columnsTemplate('1fr 1fr')
.cachedCount(40)
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
.width('100%').height('100%')
}
}
}

View File

@ -18,9 +18,9 @@ import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/library
@Component
struct ObjectFitPage {
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: $r("app.media.app_icon"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: $r('app.media.app_icon'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Fill
}
@ -29,9 +29,9 @@ struct ObjectFitPage {
Button($r('app.string.Main_image_Fill')).onClick(()=>{
this.imageKnifeOption = {
loadSrc: $r("app.media.app_icon"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: $r('app.media.app_icon'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Fill
}
})
@ -41,9 +41,9 @@ struct ObjectFitPage {
await ImageKnife.getInstance().removeAllFileCache()
this.imageKnifeOption = {
loadSrc: "https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg",
placeholderSrc: $r("app.media.app_icon"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: 'https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg',
placeholderSrc: $r('app.media.app_icon'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Fill,
placeholderObjectFit: ImageFit.Contain
}
@ -52,9 +52,9 @@ struct ObjectFitPage {
Button($r('app.string.Error_graph_None')).margin({top:10}).onClick(() => {
this.imageKnifeOption = {
loadSrc: "http://xxxxx",
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
loadSrc: 'http://xxxxx',
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Fill,
errorholderObjectFit: ImageFit.None
}

View File

@ -19,21 +19,21 @@ import { router } from '@kit.ArkUI'
struct PrefetchAndCacheCount {
build() {
Column() {
Button("cacheCount == 5")
Button('cacheCount == 5')
.onClick(()=>{
router.pushUrl({url:"pages/LazyForEachCache"})
router.pushUrl({url:'pages/LazyForEachCache'})
})
Button("cacheCount == 30")
Button('cacheCount == 30')
.margin({top:10})
.onClick(()=>{
router.pushUrl({url:"pages/LazyForEachCount"})
router.pushUrl({url:'pages/LazyForEachCount'})
})
Button("prefetch + preload")
Button('prefetch + preload')
.margin({top:10})
.onClick(()=>{
router.pushUrl({url:"pages/PrefetchAndPreload"})
router.pushUrl({url:'pages/PrefetchAndPreload'})
})
}.width("100%")
.height("100%")
}.width('100%')
.height('100%')
}
}

View File

@ -37,7 +37,7 @@ export struct PrefetchAndPreload {
}
}).width(100).height(100)
Text(`${index}`)
}.border({ width: 5 , color: "#000000"})
}.border({ width: 5 , color: '#000000'})
}
.reuseId('imageKnife')
})
@ -47,8 +47,8 @@ export struct PrefetchAndPreload {
// 列表滚动触发visibleAreaChanged实时更新预取范围触发调用prefetch、cancel接口
this.prefetcher.visibleAreaChanged(start, end)
})
.width("100%")
.height("100%")
.width('100%')
.height('100%')
.margin({ left: 10, right: 10 })
.layoutWeight(1)
}

View File

@ -1,3 +1,17 @@
/*
* 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 { router } from '@kit.ArkUI'
@Entry
@ -5,19 +19,19 @@ import { router } from '@kit.ArkUI'
struct SetMaxRequestPage {
build() {
Column() {
Button("maxRequest = 8")
Button('maxRequest = 8')
.onClick(()=>{
router.pushUrl({url:"pages/MaxRequest1"})
router.pushUrl({url:'pages/MaxRequest1'})
})
Button("maxRequest = 20")
Button('maxRequest = 20')
.onClick(()=>{
router.pushUrl({url:"pages/MaxRequest2"})
router.pushUrl({url:'pages/MaxRequest2'})
}).margin({top:20})
Button("maxRequest = 32")
Button('maxRequest = 32')
.onClick(()=>{
router.pushUrl({url:"pages/MaxRequest2"})
router.pushUrl({url:'pages/MaxRequest2'})
}).margin({top:20})
}.width("100%")
.height("100%")
}.width('100%')
.height('100%')
}
}

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -16,18 +16,18 @@ import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
@Entry
@ComponentV2
@Component
struct SignatureTestPage {
@Local imageKnifeOption1: ImageKnifeOption =new ImageKnifeOption(
@State imageKnifeOption1: ImageKnifeOption =
{
loadSrc: $r('app.media.icon'),
placeholderSrc:$r("app.media.loading"),
});
@Local imageKnifeOption2: ImageKnifeOption =new ImageKnifeOption(
placeholderSrc:$r('app.media.loading'),
};
@State imageKnifeOption2: ImageKnifeOption =
{
loadSrc: $r('app.media.icon'),
placeholderSrc:$r("app.media.loading"),
});
placeholderSrc:$r('app.media.loading'),
};
build() {
Scroll() {
@ -37,11 +37,11 @@ struct SignatureTestPage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button($r('app.string.Load'))
.onClick(() => {
this.imageKnifeOption1 = new ImageKnifeOption({
this.imageKnifeOption1 = {
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r("app.media.loading"),
signature: "1"
})
placeholderSrc:$r('app.media.loading'),
signature: '1'
}
}).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink)
@ -50,11 +50,11 @@ struct SignatureTestPage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button($r('app.string.Load'))
.onClick(() => {
this.imageKnifeOption2 = new ImageKnifeOption({
this.imageKnifeOption2 = {
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
placeholderSrc:$r("app.media.loading"),
placeholderSrc:$r('app.media.loading'),
signature: new Date().getTime().toString()
})
}
}).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink)
@ -66,7 +66,7 @@ struct SignatureTestPage {
}
aboutToAppear() {
console.log("唯一标识页面:" + new Date().getTime().toString())
console.log('唯一标识页面:' + new Date().getTime().toString())
}
}

View File

@ -20,20 +20,20 @@ import { common2D, drawing } from '@kit.ArkGraphics2D';
@Entry
@Component
struct SingleImage {
resource: string = "app.media.svgSample"
resource: string = 'app.media.svgSample'
scroller: Scroller = new Scroller;
localFile: string = getContext(this).filesDir + "/icon.png"
localFile: string = getContext(this).filesDir + '/icon.png'
@State pixelMap:PixelMap | undefined = undefined;
@State DrawingColorFilter: ColorFilter | undefined = undefined
private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
aboutToAppear(): void {
// 拷贝本地文件
let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r("app.media.startIcon"));
let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r('app.media.startIcon'));
let file = fs.openSync(this.localFile, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.writeSync(file.fd, icon.buffer);
fs.fsyncSync(file.fd);
fs.closeSync(file);
this.changePic(getContext().resourceManager.getMediaContentSync( $r("app.media.aaa"))
this.changePic(getContext().resourceManager.getMediaContentSync( $r('app.media.aaa'))
.buffer as ArrayBuffer);
@ -47,9 +47,9 @@ struct SingleImage {
.fontWeight(FontWeight.Bold)
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $r("app.media.svgSample"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
loadSrc: $r('app.media.svgSample'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
@ -62,8 +62,8 @@ struct SingleImage {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: this.localFile,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
@ -72,13 +72,13 @@ struct SingleImage {
.fontWeight(FontWeight.Bold)
ImageKnifeComponent({
imageKnifeOption: {
loadSrc:"https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
loadSrc:'https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png',
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain,
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)},
progressListener:(progress:number)=>{console.info('ImageKnife:: call back progress = ' + progress)},
// 通过https协议进行连接时默认使用系统预设CA证书。若希望使用自定义证书进行https连接则需要将自定义证书上传至应用沙箱目录中并在caPath中指定该证书所在的应用沙箱路径
// caPath: "/data/storage/el1/bundle/ca.pem",
// caPath: '/data/storage/el1/bundle/ca.pem',
}
}).width(100).height(100)
Text($r('app.string.Custom_network_download'))
@ -86,13 +86,13 @@ struct SingleImage {
.fontWeight(FontWeight.Bold)
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: "https://file.atomgit.com/uploads/user/1704857786989_8994.jpeg",
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
loadSrc: 'https://file.atomgit.com/uploads/user/1704857786989_8994.jpeg',
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain,
headerOption:[{
key:"refer",
value:"xx.xx.xx.xx"
key:'refer',
value:'xx.xx.xx.xx'
}],
customGetImage: custom,
transformation: new BlurTransformation(10)
@ -104,8 +104,8 @@ struct SingleImage {
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: this.pixelMap!,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain,
}
}).width(100).height(100)
@ -131,10 +131,10 @@ struct SingleImage {
// 自定义下载方法
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
let refer = headers!["refer"] as string
console.info("ImageKnife:: custom download" + src,"refer:"+refer)
let refer = headers!['refer'] as string
console.info('ImageKnife:: custom download' + src,'refer:'+refer)
// 举例写死从本地文件读取,也可以自己请求网络图片
let buffer = context.resourceManager.getMediaContentSync($r("app.media.startIcon").id).buffer as ArrayBuffer
let buffer = context.resourceManager.getMediaContentSync($r('app.media.startIcon').id).buffer as ArrayBuffer
return buffer
}

View File

@ -27,11 +27,11 @@ struct TestCacheDataPage {
@State markersNumText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
@State markersSizeText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
@State ImageKnifeOption: ImageKnifeOption = {
loadSrc: "",
loadSrc: '',
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadFailed: (err) => {
console.error("Load Failed Reason: " + err);
console.error('Load Failed Reason: ' + err);
},
onLoadSuccess: (data) => {
return data;
@ -41,7 +41,7 @@ struct TestCacheDataPage {
}
aboutToAppear(): void {
ImageKnife.getInstance().initFileCache(getContext(this), 256, 256 * 1024 * 1024, "ImageKnifeCache1")
ImageKnife.getInstance().initFileCache(getContext(this), 256, 256 * 1024 * 1024, 'ImageKnifeCache1')
}
build() {
@ -56,7 +56,7 @@ struct TestCacheDataPage {
Button($r('app.string.load_memory'))
.onClick(() => {
this.ImageKnifeOption = {
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg',
objectFit: ImageFit.Contain,
writeCacheStrategy: CacheStrategy.Memory,
border: { radius: 50 },
@ -65,7 +65,7 @@ struct TestCacheDataPage {
Button($r('app.string.load_disk'))
.onClick(() => {
this.ImageKnifeOption = {
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
objectFit: ImageFit.Contain,
writeCacheStrategy: CacheStrategy.File,
border: { radius: 50 },

View File

@ -102,7 +102,7 @@ struct TestChangeColorPage {
Text($r('app.string.test_svg_color')).margin({ top: 30 })
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $r("app.media.ic_test_change_color_svg"),
loadSrc: $r('app.media.ic_test_change_color_svg'),
drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN)
}
}).width(110).height(110)

View File

@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent ,ImageKnifeOption} from '@ohos/libraryimageknife';
import { ImageKnifeComponent } from '@ohos/libraryimageknife';
@Entry
@ComponentV2
@Component
struct TestCommonImage {
private data: Array<string> = []
aboutToAppear(): void {
@ -30,23 +30,23 @@ struct TestCommonImage {
FlowItem() {
Column(){
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
imageKnifeOption: {
loadSrc: item,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
objectFit: ImageFit.Contain,
signature: "aaa"
})
}).width("50%").height(200)
signature: 'aaa'
}
}).width('50%').height(200)
}
}.height(200)
.backgroundColor("#95efd2")
.backgroundColor('#95efd2')
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
}.columnsTemplate('1fr 1fr')
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
.width('100%').height('100%')
}
}
}

View File

@ -12,34 +12,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
import { ImageKnifeComponent } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestErrorHolderPage {
build() {
Column() {
Text("ImageKnifeComponent1").fontSize(20)
Text('ImageKnifeComponent1').fontSize(20)
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc",
imageKnifeOption: {
loadSrc: 'abc',
errorholderSrc:$r('app.media.failed')
})
}
}).width(200).height(200)
Text("ImageKnifeComponent2").fontSize(20)
Text('ImageKnifeComponent2').fontSize(20)
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc",
imageKnifeOption: {
loadSrc: 'abc',
errorholderSrc:$r('app.media.startIcon')
})
}
}).width(200).height(200)
Text("ImageKnifeComponent2").fontSize(20)
Text('ImageKnifeComponent2').fontSize(20)
ImageKnifeComponent({
imageKnifeOption: new ImageKnifeOption({
loadSrc: "abc",
imageKnifeOption: {
loadSrc: 'abc',
errorholderSrc:$r('app.media.mask_starfish')
})
}
}).width(200).height(200)
}
.height('100%') .width('100%')

View File

@ -15,18 +15,18 @@
import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestPrefetchToFileCachePage {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
@State imageKnifeOption: ImageKnifeOption = {
loadSrc:'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
placeholderSrc:$r('app.media.loading'),
headerOption:[
{
key:"abc",
value:"单个"
key:'abc',
value:'单个'
}
]
})
}
build() {
Column() {

View File

@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IndexComponent } from "@ohos/libraryimageknife"
import { IndexComponent } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestHspPreLoadImage {
build() {
Column() {
IndexComponent()
}.width("100%").height('100%')
IndexComponent()
}.width('100%').height('100%')
}
}

View File

@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife'
import { ImageKnifeComponent } from '@ohos/libraryimageknife'
@ObservedV2
@Observed
export class MsgModel {
id: string
cId: string
@ -30,66 +30,66 @@ export class MsgModel {
}
// @Reusable
@ComponentV2
@Reusable
@Component
export struct MsgItem {
@Param count: number = 0
count: number = 0
private data: Array<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",
'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',
]
build(){
if (this.count % 2 == 0 && this.count <6){
ImageKnifeComponent({
imageKnifeOption:new ImageKnifeOption({
loadSrc:$r("app.media.startIcon"),
placeholderSrc:$r("app.media.loading")
}),syncLoad:true
imageKnifeOption:{
loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading')
},syncLoad:true
})
}else if (this.count > 6 && this.count - 6 < this.data.length){
ImageKnifeComponent({
imageKnifeOption:new ImageKnifeOption({
imageKnifeOption:{
loadSrc:this.data[this.count - 6],
placeholderSrc:$r("app.media.loading")
}),syncLoad:true
placeholderSrc:$r('app.media.loading')
},syncLoad:true
})
}else {
ImageKnifeComponent({
imageKnifeOption:new ImageKnifeOption({
loadSrc:$r("app.media.pngSample"),
placeholderSrc:$r("app.media.loading")
}),syncLoad:true
imageKnifeOption:{
loadSrc:$r('app.media.pngSample'),
placeholderSrc:$r('app.media.loading')
},syncLoad:true
})
}
}
}
@Entry
@ComponentV2
@Component
struct ImageTestPage {
count : number = 0
rCount: number = 0
scroller: Scroller = new Scroller()
@Local list: MsgModel[] = []
@Local imageSize: number =100
@State list: MsgModel[] = []
@State imageSize: number =100
handAdd(){
this.count++
const msgItem = new MsgModel('add_id'+this.count, 'addBody'+this.count,'cId'+ this.count)
@ -103,10 +103,10 @@ struct ImageTestPage {
build(){
Column(){
Row(){
Button("addItem").onClick(()=> {
Button('addItem').onClick(()=> {
this.handAdd()
})
Button("remove").onClick(()=> {
Button('remove').onClick(()=> {
this.list.splice(0,1)
})
}

View File

@ -20,37 +20,37 @@ import { router } from '@kit.ArkUI';
@Component
struct TestImageKnifeCallbackPage {
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: "",
loadSrc: '',
objectFit: ImageFit.Contain,
border: { radius: 50 }
};
@State currentWidth: number = 200
@State currentHeight: number = 200
@State url: string | undefined = ""
@State imageType: string | undefined = ""
@State url: string | undefined = ''
@State imageType: string | undefined = ''
@State imageWidth: number | undefined = 0
@State imageHeight: number | undefined = 0
@State imageSize: number | undefined = 0
@State componentWidth: number | undefined = 0
@State componentHeight: number | undefined = 0
@State frameNum: number | undefined = 0
@State decodeSize: string | undefined = ""
@State err_msg: string | undefined = ""
@State err_phase: string | undefined = ""
@State err_code: number | undefined = 0
@State http_code: number | undefined = 0
@State reqStartTime: string | undefined = ""
@State reqEndTime: string | undefined = ""
@State reqCancelTime: string | undefined = ""
@State memoryStartTime: string | undefined = ""
@State memoryEndTime: string | undefined = ""
@State diskStartTime: string | undefined = ""
@State diskEndTime: string | undefined = ""
@State netStartTime: string | undefined = ""
@State netEndTime: string | undefined = ""
@State decodeStartTime: string | undefined = ""
@State decodeEndTime: string | undefined = ""
@State renderTime: string | undefined = ""
@State decodeSize: string | undefined = ''
@State errMsg: string | undefined = ''
@State errPhase: string | undefined = ''
@State errCode: number | undefined = 0
@State httpCode: number | undefined = 0
@State reqStartTime: string | undefined = ''
@State reqEndTime: string | undefined = ''
@State reqCancelTime: string | undefined = ''
@State memoryStartTime: string | undefined = ''
@State memoryEndTime: string | undefined = ''
@State diskStartTime: string | undefined = ''
@State diskEndTime: string | undefined = ''
@State netStartTime: string | undefined = ''
@State netEndTime: string | undefined = ''
@State decodeStartTime: string | undefined = ''
@State decodeEndTime: string | undefined = ''
@State renderTime: string | undefined = ''
@State showChild: boolean = true;
build() {
@ -61,10 +61,10 @@ struct TestImageKnifeCallbackPage {
Text($r('app.string.componentWH', this.componentWidth, this.componentHeight)).fontSize(14)
Text($r('app.string.img_frame', this.frameNum)).fontSize(14)
Text($r('app.string.img_content_size', this.decodeSize)).fontSize(14)
Text($r('app.string.err_msg', this.err_msg)).fontSize(14)
Text($r('app.string.err_phase', this.err_phase)).fontSize(14)
Text($r('app.string.err_code', this.err_code)).fontSize(14)
Text($r('app.string.http_code', this.http_code)).fontSize(14)
Text($r('app.string.err_msg', this.errMsg)).fontSize(14)
Text($r('app.string.err_phase', this.errPhase)).fontSize(14)
Text($r('app.string.err_code', this.errCode)).fontSize(14)
Text($r('app.string.http_code', this.httpCode)).fontSize(14)
Text($r('app.string.req_start_time', this.reqStartTime)).fontSize(14)
Text($r('app.string.req_end_time', this.reqEndTime)).fontSize(14)
Text($r('app.string.req_cancel_time', this.reqCancelTime)).fontSize(14)
@ -87,7 +87,7 @@ struct TestImageKnifeCallbackPage {
.onClick(() => {
this.destroy();
this.imageKnifeOption = {
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg',
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: (data) => {
@ -178,7 +178,7 @@ struct TestImageKnifeCallbackPage {
.onClick(() => {
this.destroy();
this.imageKnifeOption = {
loadSrc: "https://img-blog.csdn.net/20140514114039140",
loadSrc: 'https://img-blog.csdn.net/20140514114039140',
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: (data) => {
@ -268,7 +268,7 @@ struct TestImageKnifeCallbackPage {
.onClick(() => {
this.destroy();
this.imageKnifeOption = {
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg",
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: (data) => {
@ -364,10 +364,10 @@ struct TestImageKnifeCallbackPage {
analyzeFailedBackData(res: string, data: ImageKnifeData | undefined) {
if (data) {
this.err_msg = res;
this.err_phase = data.errorInfo?.phase;
this.err_code = data.errorInfo?.code;
this.http_code = data.errorInfo?.httpCode;
this.errMsg = res;
this.errPhase = data.errorInfo?.phase;
this.errCode = data.errorInfo?.code;
this.httpCode = data.errorInfo?.httpCode;
this.reqEndTime = this.formatDate(data.timeInfo?.requestEndTime);
this.diskStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
this.diskEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
@ -382,31 +382,31 @@ struct TestImageKnifeCallbackPage {
destroy() {
this.currentWidth = 200
this.currentHeight = 200
this.url = ""
this.imageType = ""
this.url = ''
this.imageType = ''
this.imageWidth = 0
this.imageHeight = 0
this.imageSize = 0
this.componentWidth = 0
this.componentHeight = 0
this.frameNum = 0
this.decodeSize = ""
this.err_msg = ""
this.err_phase = ""
this.err_code = 0
this.http_code = 0
this.reqStartTime = ""
this.reqEndTime = ""
this.reqCancelTime = ""
this.memoryStartTime = ""
this.memoryEndTime = ""
this.diskStartTime = ""
this.diskEndTime = ""
this.netStartTime = ""
this.netEndTime = ""
this.decodeStartTime = ""
this.decodeEndTime = ""
this.renderTime = ""
this.decodeSize = ''
this.errMsg = ''
this.errPhase = ''
this.errCode = 0
this.httpCode = 0
this.reqStartTime = ''
this.reqEndTime = ''
this.reqCancelTime = ''
this.memoryStartTime = ''
this.memoryEndTime = ''
this.diskStartTime = ''
this.diskEndTime = ''
this.netStartTime = ''
this.netEndTime = ''
this.decodeStartTime = ''
this.decodeEndTime = ''
this.renderTime = ''
this.showChild = true;
}
}

View File

@ -15,37 +15,37 @@
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestIsUrlExist {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
})
@Local source: PixelMap | string | Resource = $r("app.media.startIcon")
@Local source1: PixelMap | string | Resource = $r("app.media.startIcon")
}
@State source: PixelMap | string | Resource = $r('app.media.startIcon')
@State source1: PixelMap | string | Resource = $r('app.media.startIcon')
build() {
Column() {
Flex() {
Button($r('app.string.Preloading_GIF')).onClick(() => {
this.imageKnifeOption.loadSrc =
"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658"
'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658'
})
Button($r('app.string.Retrieve_GIF_from_memory')).onClick(() => {
ImageKnife.getInstance()
.getCacheImage("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
.getCacheImage('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
CacheStrategy.Memory)
.then((data) => {
this.source = data !== undefined ? data.source : $r("app.media.startIcon")
this.source = data !== undefined ? data.source : $r('app.media.startIcon')
})
})
Button($r('app.string.Retrieve_GIF_from_disk')).onClick(() => {
ImageKnife.getInstance()
.getCacheImage("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
.getCacheImage('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
CacheStrategy.File)
.then((data) => {
this.source1 = data !== undefined ? data.source : $r("app.media.startIcon")
this.source1 = data !== undefined ? data.source : $r('app.media.startIcon')
})
})
}

View File

@ -16,9 +16,9 @@
import { ImageKnifeComponent} from '@ohos/libraryimageknife';
class ArrayElement {
src: string = "";
w: number = 0;
h: number = 0;
public src: string = '';
public w: number = 0;
public h: number = 0;
}
@Entry
@ -27,27 +27,27 @@ struct TestListImageKnifeCallbackPage {
private wid: number = 200;
private hig: number = 200;
private dataArray: ESObject[] = [
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg",
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg',
'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
'https://img-blog.csdn.net/20140514114029140',
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
@ -78,17 +78,19 @@ struct TestListImageKnifeCallbackPage {
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: (data) => {
console.log("listCache start:{ url:"+data?.imageKnifeOption.loadSrc +",componentWidth:"+data?.componentWidth+",componentHeight:"+data?.componentHeight+"},"
+ JSON.stringify(data?.getImageKnifeData()))
console.log('listCache start:{ url:' + data?.imageKnifeOption.loadSrc +
',componentWidth:' + data?.componentWidth +
',componentHeight:' + data?.componentHeight +
'},' + JSON.stringify(data?.getImageKnifeData()))
},
onLoadFailed: (res, req) => {
console.log("listCache onLoadFailed:res:" + res + ";" + JSON.stringify(req?.getImageKnifeData()))
console.log('listCache onLoadFailed:res:' + res + ';' + JSON.stringify(req?.getImageKnifeData()))
},
onLoadSuccess: (data, imageData,req) => {
console.log("listCache onLoadSuccess:" + JSON.stringify(req?.getImageKnifeData()))
console.log('listCache onLoadSuccess:' + JSON.stringify(req?.getImageKnifeData()))
},
onLoadCancel: (res, req) => {
console.log("listCache onLoadCancel:res:" + res + ";" + JSON.stringify(req?.getImageKnifeData()))
console.log('listCache onLoadCancel:res:' + res + ';' + JSON.stringify(req?.getImageKnifeData()))
}
},
border: { radius: 50 },

View File

@ -22,9 +22,9 @@ struct TestLoadCancelListenerPage {
@State currentWidth: number = 200
@State currentHeight: number = 200
@State showChild: boolean = true;
@State text: string = "";
@State text: string = '';
@State ImageKnifeOption: ImageKnifeOption = {
loadSrc: "",
loadSrc: '',
objectFit: ImageFit.Contain,
border: { radius: 50 }
};
@ -37,7 +37,7 @@ struct TestLoadCancelListenerPage {
.onClick(() => {
this.clearCache();
this.ImageKnifeOption = {
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg',
objectFit: ImageFit.Contain,
onLoadListener: {
onLoadStart: () => {
@ -45,7 +45,7 @@ struct TestLoadCancelListenerPage {
},
onLoadCancel: (res) => {
this.text = res
console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res)
console.log('TestLoadCancelListenerPage----onLoadCancel> url:' + res)
}
},
border: { radius: 50 }
@ -54,10 +54,10 @@ struct TestLoadCancelListenerPage {
Button($r('app.string.component_display'))
.margin(20).onClick(() => {
this.text = "";
this.text = '';
this.showChild = true;
this.ImageKnifeOption = {
loadSrc: "",
loadSrc: '',
objectFit: ImageFit.Contain,
border: { radius: 50 }
}
@ -75,7 +75,7 @@ struct TestLoadCancelListenerPage {
},
onLoadCancel: (res) => {
this.text = res
console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res)
console.log('TestLoadCancelListenerPage----onLoadCancel> url:' + res)
}
},
border: { radius: 50 }

View File

@ -15,31 +15,31 @@
import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestPrefetchToFileCachePage {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
@State imageKnifeOption: ImageKnifeOption = {
loadSrc:$r('app.media.startIcon'),
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
})
}
async preload(url:string) {
let fileCachePath = await ImageKnife.getInstance().preLoadCache(url)
console.log("preload-fileCachePath=="+ fileCachePath)
console.log('preload-fileCachePath=='+ fileCachePath)
}
async preload1(url:string) {
let fileCachePath = await ImageKnife.getInstance().preLoadCache(new ImageKnifeOption({ loadSrc: url }))
console.log("preload-fileCachePath1=="+ fileCachePath)
let fileCachePath = await ImageKnife.getInstance().preLoadCache({ loadSrc: url })
console.log('preload-fileCachePath1=='+ fileCachePath)
}
build() {
Column() {
Button($r('app.string.Preloading_images_to_file_cache_using_URL')).margin({top:10}).onClick(async ()=>{
await this.preload("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658")
await this.preload('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658')
})
Button($r('app.string.Preloading_images_to_file_cache_using_option')).margin({top:10}).onClick(async ()=>{
await this.preload1("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658")
await this.preload1('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658')
})
Button($r('app.string.Load_image_offline_after_preloading')).margin({top:10}).onClick(()=>{
this.imageKnifeOption.loadSrc = "https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658"
this.imageKnifeOption.loadSrc = 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658'
})
ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption

View File

@ -15,40 +15,40 @@
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife'
@Entry
@ComponentV2
@Component
struct TestRemoveCache {
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
@State imageKnifeOption: ImageKnifeOption = {
loadSrc: $r('app.media.startIcon'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc:$r('app.media.failed')
})
@Local source: PixelMap | string | Resource = $r("app.media.startIcon");
@Local source1: PixelMap | string | Resource = $r("app.media.startIcon");
@Local url: string = '';
}
@State source: PixelMap | string | Resource = $r('app.media.startIcon');
@State source1: PixelMap | string | Resource = $r('app.media.startIcon');
@State url: string = '';
build() {
Column() {
Flex() {
Button($r('app.string.Preloading_GIF')).onClick(() => {
this.imageKnifeOption.loadSrc = "https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658";
this.url = "https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658";
this.imageKnifeOption.loadSrc = 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658';
this.url = 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658';
})
.margin({left:10})
Button($r('app.string.Retrieve_GIF_from_memory')).onClick(() => {
ImageKnife.getInstance()
.getCacheImage("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
.getCacheImage('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
CacheStrategy.Memory)
.then((data) => {
this.source = data !== undefined ? data.source : $r("app.media.startIcon");
this.source = data !== undefined ? data.source : $r('app.media.startIcon');
})
})
.margin({left:10})
Button($r('app.string.Retrieve_GIF_from_disk')).onClick(() => {
ImageKnife.getInstance()
.getCacheImage("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
.getCacheImage('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
CacheStrategy.File)
.then((data) => {
this.source1 = data !== undefined ? data.source : $r("app.media.startIcon");
this.source1 = data !== undefined ? data.source : $r('app.media.startIcon');
})
})
.margin({left:10})

View File

@ -32,21 +32,21 @@ struct TestSetCustomImagePage {
}
build() {
Column() {
Button(this.getResourceString($r('app.string.Custom_network_download')) + " a").onClick(()=>{
Button(this.getResourceString($r('app.string.Custom_network_download')) + ' a').onClick(()=>{
this.imageKnifeOption ={
loadSrc: "aaa",
loadSrc: 'aaa',
placeholderSrc: $r('app.media.loading')
}
})
Button(this.getResourceString($r('app.string.Custom_network_download')) + " b").onClick(()=>{
Button(this.getResourceString($r('app.string.Custom_network_download')) + ' b').onClick(()=>{
this.imageKnifeOption = {
loadSrc: "bbb",
loadSrc: 'bbb',
placeholderSrc: $r('app.media.loading')
}
})
Button(this.getResourceString($r('app.string.Custom_network_download')) + " c").onClick(()=>{
Button(this.getResourceString($r('app.string.Custom_network_download')) + ' c').onClick(()=>{
this.imageKnifeOption = {
loadSrc: "ccc",
loadSrc: 'ccc',
placeholderSrc: $r('app.media.loading')
}
})
@ -55,14 +55,14 @@ struct TestSetCustomImagePage {
}).width(300)
.height(300)
}
.width("100%")
.height("100%")
.width('100%')
.height('100%')
}
}
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
console.info("ImageKnife:: custom download" + src)
console.info('ImageKnife:: custom download' + src)
// 举例写死从本地文件读取,也可以自己请求网络图片
let buffer = context.resourceManager.getMediaContentSync($r("app.media.pngSample").id).buffer as ArrayBuffer
let buffer = context.resourceManager.getMediaContentSync($r('app.media.pngSample').id).buffer as ArrayBuffer
return buffer
}

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
@ComponentV2
export struct ZuImage {
@ -43,7 +43,7 @@ export struct ZuImage {
@ComponentV2
struct TestTaskResourcePage {
@Local stateMenus: Array<string> = [
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
'https://img-blog.csdn.net/20140514114029140',
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
@ -53,7 +53,7 @@ struct TestTaskResourcePage {
Column({ space: 8 }) {
ZuImage({
src: item,
placeholderSrc: $r("app.media.loading")
placeholderSrc: $r('app.media.loading')
}).width(44)
.height(44)
}
@ -66,7 +66,7 @@ struct TestTaskResourcePage {
this._buildItem(item)
}
})
}.width("100%")
}.width('100%')
.columnsTemplate('1fr 1fr 1fr 1fr 1fr')
.rowsGap(24)
.padding({

View File

@ -48,7 +48,7 @@ struct TestWriteCacheStage {
}).width(200).height(200).margin({top:10})
Button($r('app.string.Write_memory')).margin({top:10}).onClick(async ()=>{
this.imageKnifeOption2 = {
loadSrc:"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
loadSrc:'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
placeholderSrc:$r('app.media.loading'),
errorholderSrc:$r('app.media.failed'),
writeCacheStrategy:CacheStrategy.Memory

View File

@ -12,22 +12,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
import matrix4 from '@ohos.matrix4'
@Entry
@ComponentV2
@Component
struct TransformPage {
private custom_scale:number = 1
@Local matrix1:object = matrix4.identity().scale({ x: 1, y: 1 })
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
loadSrc: $r("app.media.rabbit"),
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.app_icon"),
@State matrix1:object = matrix4.identity().scale({ x: 1, y: 1 })
@State ImageKnifeOption: ImageKnifeOption = {
loadSrc: $r('app.media.rabbit'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.app_icon'),
objectFit: ImageFit.Contain,
border: { radius: 50 }
})
}
build() {
Column() {

View File

@ -15,50 +15,24 @@
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
// const logger = new imUtils.logger.IMLogger('Avatar')
@ObservedV2
export class MyStorage {
static instance:MyStorage | undefined = undefined
static getInstance(){
if(MyStorage.instance == undefined) {
MyStorage.instance = new MyStorage()
}
return MyStorage.instance
}
@Trace WeLink_Mob_fontSize_multiple: number = 1
class MyImageOption extends ImageKnifeOption {
account?: string
}
@ComponentV2
@Component
export struct UserAvatar {
// @Prop userInfo: string = ""
@Prop @Watch('userInfoUpdate') userInfo: string = ''
// @Prop userInfo: string = ''
imgSize: number = 100
radius: number = 12
borderSize: number = 0
imgSizes: number = 1
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
@State ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
@StorageProp('WeLink_Mob_fontSize_multiple') @Watch('updateImgSize') WeLink_Mob_fontSize_multiple: number = 0
scalable: boolean = true;
@Local calcImgSize: number = 100
@Param userInfo: string = ""
@Monitor('userInfo')
userInfoUpdate() {
// if (uri === 'userInfo' && this.imageKnifeOption.account !== this.userInfo.contactId) return;
// // logger.info(`userInfoUpdate uri=${uri} oldAcc=${this.imageKnifeOption.loadSrc} nowAcc=${this.userInfo.externalHeadUrl}`)
// if (this.userInfo.externalHeadUrl === this.imageKnifeOption.loadSrc && this.userInfo.infoUpdateTime.getTime()
// .toString() === this.imageKnifeOption?.signature?.getKey()) return;
this.ImageKnifeOption = new ImageKnifeOption({
//TODO:写死loadSRC场景变更组件大小所有图片不显示
loadSrc: this.userInfo,
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
border: { radius:20,width:5,color:$r('app.color.start_window_background') },
objectFit:ImageFit.Contain
// signature: new ObjectKey(this.userInfo.infoUpdateTime.getTime().toString())
})
}
@Local storage: MyStorage = MyStorage.getInstance()
@Monitor('storage.WeLink_Mob_fontSize_multiple')
updateImgSize() {
this.setImageSize()
}
@State calcImgSize: number = 100
aboutToAppear(): void {
this.userInfoUpdate()
this.setImageSize()
@ -67,19 +41,39 @@ export struct UserAvatar {
setImageSize() {
if (!this.scalable) {
this.calcImgSize = this.imgSize
} else if (this.storage.WeLink_Mob_fontSize_multiple < 0.9) {
} else if (this.WeLink_Mob_fontSize_multiple < 0.9) {
this.calcImgSize = this.imgSize * 0.9
} else if (this.storage.WeLink_Mob_fontSize_multiple > 1.6) {
} else if (this.WeLink_Mob_fontSize_multiple > 1.6) {
this.calcImgSize = this.imgSize * 1.6
} else {
this.calcImgSize = this.imgSize * this.storage.WeLink_Mob_fontSize_multiple
this.calcImgSize = this.imgSize * this.WeLink_Mob_fontSize_multiple
}
}
updateImgSize() {
this.setImageSize()
}
aboutToReuse(param: ESObject) {
this.userInfoUpdate()
}
userInfoUpdate() {
// if (uri === 'userInfo' && this.imageKnifeOption.account !== this.userInfo.contactId) return;
// // logger.info(`userInfoUpdate uri=${uri} oldAcc=${this.imageKnifeOption.loadSrc} nowAcc=${this.userInfo.externalHeadUrl}`)
// if (this.userInfo.externalHeadUrl === this.imageKnifeOption.loadSrc && this.userInfo.infoUpdateTime.getTime()
// .toString() === this.imageKnifeOption?.signature?.getKey()) return;
this.ImageKnifeOption = {
//TODO:写死loadSRC场景变更组件大小所有图片不显示
loadSrc: this.userInfo,
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed'),
border: { radius:20,width:5,color:$r('app.color.start_window_background') },
objectFit:ImageFit.Contain
// signature: new ObjectKey(this.userInfo.infoUpdateTime.getTime().toString())
}
}
build() {
Row() {
// Image(this.imageKnifeOption.loadSrc)
@ -93,12 +87,12 @@ export struct UserAvatar {
// Image(this.userInfo)
// Text((this.imageKnifeOption.loadSrc as string).split('/')[8])
// .position({ x: 0, y: 0 })
// .zIndex(9)
// .fontSize(12)
// .fontColor('#ff0000')
// Image(this.userInfo)
// Text((this.imageKnifeOption.loadSrc as string).split('/')[8])
// .position({ x: 0, y: 0 })
// .zIndex(9)
// .fontSize(12)
// .fontColor('#ff0000')
}
}
}

View File

@ -20,58 +20,58 @@ import { UserAvatar } from './User'
struct Index {
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
private data:string[] = [
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg",
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg",
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg',
'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
'https://img-blog.csdn.net/20140514114029140',
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
]
aboutToAppear(): void {
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data)
AppStorage.set("WeLink_Mob_fontSize_multiple",1)
AppStorage.set('WeLink_Mob_fontSize_multiple',1)
}
build() {
Column() {
Button("bigger").onClick(()=>{
AppStorage.set("WeLink_Mob_fontSize_multiple",1.6)
Button('bigger').onClick(()=>{
AppStorage.set('WeLink_Mob_fontSize_multiple',1.6)
})
Button("small").onClick(()=>{
AppStorage.set("WeLink_Mob_fontSize_multiple",0.8)
Button('small').onClick(()=>{
AppStorage.set('WeLink_Mob_fontSize_multiple',0.8)
})
List(){
LazyForEach(this.hotCommendList,(item:string)=>{
ListItem(){
ReuseImage({
userInfo:item
}).width("100%").height("100%").backgroundColor(Color.Yellow)
}).width('100%').height('100%').backgroundColor(Color.Yellow)
}.width(200).height(200).margin({bottom:5})
})
}
// .cachedCount(20)
.width("100%")
.height("100%")
.width('100%')
.height('100%')
.backgroundColor(0xFAEEE0)
}.width('100%').height("100%")
}.width('100%').height('100%')
}
}
@ -79,7 +79,7 @@ struct Index {
@Reusable
@Component
struct ReuseImage {
@State userInfo:string = ""
@State userInfo:string = ''
aboutToReuse(params: ESObject): void {
this.userInfo = params.userInfo
}
@ -89,6 +89,6 @@ struct ReuseImage {
UserAvatar({
userInfo:this.userInfo
})
}.width("100%").height("100%")
}.width('100%').height('100%')
}
}

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -18,15 +18,15 @@ import { photoAccessHelper } from '@kit.MediaLibraryKit';
@Entry
@ComponentV2
@Component
struct DataShareUriLoadPage {
@Local imageKnifeOption1: ImageKnifeOption =
new ImageKnifeOption({
@State imageKnifeOption1: ImageKnifeOption =
{
loadSrc: $r('app.media.icon'),
placeholderSrc: $r('app.media.loading'),
errorholderSrc: $r('app.media.failed')
});
};
build() {
@ -43,10 +43,10 @@ struct DataShareUriLoadPage {
let photoViewPicker = new photoAccessHelper.PhotoViewPicker();
let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoViewPicker.select(photoSelectOptions);
uris = photoSelectResult.photoUris;
this.imageKnifeOption1 = new ImageKnifeOption({
this.imageKnifeOption1 = {
loadSrc: uris[0],
placeholderSrc:$r('app.media.loading')
})
}
}).margin({ top: 5, left: 3 })
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300)
}.width('100%').backgroundColor(Color.Pink)

View File

@ -12,8 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { statfs } from '@kit.CoreFileKit'
import { rcp } from '@kit.RemoteCommunicationKit'
export class CommonDataSource <T> implements IDataSource {
private dataArray: T[] = []
@ -54,7 +52,4 @@ export class CommonDataSource <T> implements IDataSource {
listener.onDataAdd(index)
})
}
}
export class GetSession {
static session:rcp.Session = rcp.createSession()
}

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {ImageKnife, ImageKnifeRequest} from "@ohos/libraryimageknife"
import {ImageKnife, ImageKnifeRequest} from '@ohos/libraryimageknife'
import { IDataSourcePrefetching } from '@kit.ArkUI';
import { HashMap } from '@kit.ArkTS';
@ -61,7 +61,7 @@ export default class DataSourcePrefetchingImageKnife implements IDataSourcePrefe
}
async prefetch(index: number): Promise<void> {
let item = this.dataArray[index]
if (typeof item.albumUrl == "string") {
if (typeof item.albumUrl == 'string') {
// 图片预加载
let request = ImageKnife.getInstance().preload({
loadSrc:item.albumUrl,

View File

@ -17,127 +17,127 @@ import { InfoItem } from './DataSourcePrefetching'
export class PageViewModel {
private static dataArray: Array<InfoItem> = [
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/8a/v3/ZKzYV5BJTuCk5hCE0y_xNA/8JT95OQnSZSd6_xQQUONhQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/8a/v3/ZKzYV5BJTuCk5hCE0y_xNA/8JT95OQnSZSd6_xQQUONhQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/1/v3/sTXb_I7URBKjdMyLDYa19w/qpcwa_FNQmi3-EzjbGsJ8A.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/1/v3/sTXb_I7URBKjdMyLDYa19w/qpcwa_FNQmi3-EzjbGsJ8A.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e5/v3/m7wFvw_eQIuDV0Mk0IKi8g/gJU4migzTHKYk5KrgdZbBw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e5/v3/m7wFvw_eQIuDV0Mk0IKi8g/gJU4migzTHKYk5KrgdZbBw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3f/v3/k_UWbB5_RGW7JemQZ0OQdw/_DUdmaZRQyG-Oyvkb663Bw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3f/v3/k_UWbB5_RGW7JemQZ0OQdw/_DUdmaZRQyG-Oyvkb663Bw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/39/v3/rFRN7G_VSo-p4mBjTZtkRw/gBwTI-ieSIqSsSmLNBEcgw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/39/v3/rFRN7G_VSo-p4mBjTZtkRw/gBwTI-ieSIqSsSmLNBEcgw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/04/v3/6K8BPYKVQFOr7KCuAG9nog/qKd3pZlrQy2M-feB3ycVPA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/04/v3/6K8BPYKVQFOr7KCuAG9nog/qKd3pZlrQy2M-feB3ycVPA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/7d/v3/f0GQFzm1T6eduVeMUhO3Wg/-4cvzIJiRCegjIno3ofIbQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/7d/v3/f0GQFzm1T6eduVeMUhO3Wg/-4cvzIJiRCegjIno3ofIbQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e4/v3/C0xxsSeySxW-2iYR5OEbpQ/f1GlaD3zTeKPX8Vd-M1oVQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e4/v3/C0xxsSeySxW-2iYR5OEbpQ/f1GlaD3zTeKPX8Vd-M1oVQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/c2/v3/32LCyXN4TuWKWcdf9gAwWw/ej14_BCJQNCaWOKoI9aZAw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/c2/v3/32LCyXN4TuWKWcdf9gAwWw/ej14_BCJQNCaWOKoI9aZAw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fd/v3/LyYJMdMmQNaC5GyBYEZ5Pw/uFLiovypRSagKyIS-UJPVw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fd/v3/LyYJMdMmQNaC5GyBYEZ5Pw/uFLiovypRSagKyIS-UJPVw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/15/v3/MHM9KaWGTgubn6M8-B_6nw/1YO9JyYhTHSBWsoiqYkGZw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/15/v3/MHM9KaWGTgubn6M8-B_6nw/1YO9JyYhTHSBWsoiqYkGZw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/4c/v3/UdYfbv1_QYqn_ulDHp89OA/VkjexMluTqGO3yt3gPK1DA.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/4c/v3/UdYfbv1_QYqn_ulDHp89OA/VkjexMluTqGO3yt3gPK1DA.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e8/v3/N8blT_7qSK-tRtahIyov7g/M_kjGEEmSzOlTc47Zrfozg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e8/v3/N8blT_7qSK-tRtahIyov7g/M_kjGEEmSzOlTc47Zrfozg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/28/v3/VS_h3m4YRrSgbgxnqE3vtQ/h-2Q1Qy2SSGEuXM36-Rq_w.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/28/v3/VS_h3m4YRrSgbgxnqE3vtQ/h-2Q1Qy2SSGEuXM36-Rq_w.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/2e/v3/R-BaM5ToRNGq5rwtNTcnww/Q2e01VHiR2y9KtFaZmpmNQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/2e/v3/R-BaM5ToRNGq5rwtNTcnww/Q2e01VHiR2y9KtFaZmpmNQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/88/v3/3djkAJKKTdC539XqMdstSg/wHO7DxvXQS2xbt2Y_-4BNg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/88/v3/3djkAJKKTdC539XqMdstSg/wHO7DxvXQS2xbt2Y_-4BNg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/guw4eiggR3uWjscFTxITYg/TzRB35iPTdCztrZUUaNuFg.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/guw4eiggR3uWjscFTxITYg/TzRB35iPTdCztrZUUaNuFg.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/93/v3/UvSh_f1LT66i0-3hvsYN_A/eYnE3Z8YT5Sk7F-vS2ZmCQ.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/93/v3/UvSh_f1LT66i0-3hvsYN_A/eYnE3Z8YT5Sk7F-vS2ZmCQ.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/5/v3/tv8Vqf9hQrKpozGeZWg2mw/VEICB-bmQYi0Iv6TGADbhw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/5/v3/tv8Vqf9hQrKpozGeZWg2mw/VEICB-bmQYi0Iv6TGADbhw.jpg'
},
{
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/4v1Ot5BRR6OFVQ9MGn9Xxg/xrPgRn0LS1ep-r7ewIuwiw.jpg"
albumUrl: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/4v1Ot5BRR6OFVQ9MGn9Xxg/xrPgRn0LS1ep-r7ewIuwiw.jpg'
},
]
static getItems() {

View File

@ -3,7 +3,6 @@
"pages/Index",
"pages/ListPage",
"pages/SingleImage",
"pages/ManyPhotoShowPage",
"pages/LongImagePage",
"pages/TransformPage",
"pages/UserPage",
@ -32,7 +31,6 @@
"pages/TestCacheDataPage",
"pages/TestChangeColorPage",
"pages/TestLoadCancelListenerPage",
"pages/CustomNetImagePage",
"pages/SetMaxRequestPage",
"pages/MaxRequest1",
"pages/MaxRequest2",

View File

@ -14,7 +14,7 @@
*/
import DefaultJobQueueTest from './DefaultJobQueueTest.test';
import FileLruCacheTest from './FileLruCache.test';
import ImageKnifeOptionTest from './ImageKnifeOption.test';
import ImageKnifeOptionTest from './ImageknifeOption.test';
import MemoryLruCacheTest from './MemoryLruCache.test';
import ImageKnifeTest from './ImageKnife.test';
import Transform from './transform.test';

View File

@ -1,52 +0,0 @@
/*
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { SendableData } from '@ohos/imageknife/src/main/ets/components/imageknife/SendableData'
export default function SendableDataTest() {
describe('SendableDataTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('TestPlaceHolderCacheKey', 0, () => {
let value: string = "placeholderRegisterCacheKey";
let data: SendableData = new SendableData();
data.setPlaceHolderRegisterCacheKey(value);
expect(data.getPlaceHolderRegisterCacheKey()).assertEqual(value);
})
it('TestPlaceHolderMemoryCacheKey', 1, () => {
let value: string = "placeholderRegisterMemoryCacheKey";
let data: SendableData = new SendableData();
data.setPlaceHolderRegisterMemoryCacheKey(value);
expect(data.getPlaceHolderRegisterMemoryCacheKey()).assertEqual(value);
})
})
}

View File

@ -1,106 +0,0 @@
/*
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { DownloadClient } from '@ohos/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient';
import common from '@ohos.app.ability.common';
import { GlobalContext } from '../testability/GlobalContext';
import { CustomDataFetchClient, DataFetchResult, ImageKnifeGlobal, RequestOption } from '@ohos/imageknife';
const BASE_COUNT: number = 2000;
export default function CustomDataFetchClientTest() {
describe('CustomDataFetchClientTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('TestIsLocalLoadSrc', 0, () => {
let path = 'invalid path';
let client = new DownloadClient()
expect(client.isLocalLoadSrc(undefined, path)).assertFalse();
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
if (context != undefined) {
let loadSrc1 = (context as common.UIAbilityContext).filesDir + 'a.jpg';
let loadSrc2 = (context as common.UIAbilityContext).cacheDir + 'b.jpg';
expect(client.isLocalLoadSrc(context, loadSrc1)).assertTrue();
expect(client.isLocalLoadSrc(context, loadSrc2)).assertTrue();
}
})
it('TestLoadData', 1, async () => {
let client = new CustomDataFetchClient();
let request = new RequestOption();
request.loadSrc = $r('app.media.icon');
let error = (await client.loadData(request) as DataFetchResult).error as String;
expect(error).assertEqual('CustomDataFetchClient request or loadSrc error.');
})
it('TestLoadData_customGetImage', 2, async () => {
let client = new CustomDataFetchClient();
let request = new RequestOption();
request.loadSrc = 'http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg';
request.customGetImage = (context: Context, src: string) => {
// 这里是模拟的customGetImage逻辑
return Promise.resolve(new DataFetchResult());
}
console.log('LXH', 'TestLoadData 2 --1 customGetImage is undefined ?' + (request.customGetImage == undefined));
let context: object | undefined = GlobalContext.getInstance().getObject("hapContext");
let result = await client.loadData(request);
if (context != undefined) {
console.log('LXH', 'TestLoadData 2 --2');
expect(typeof result)
.assertEqual(typeof (await request?.customGetImage(context as common.UIAbilityContext, request.loadSrc)));
}
})
it('TestLoadData_combineArrayBuffers', 3, () => {
// 创建几个ArrayBuffer作为测试数据
const arrayBuffer1 = new ArrayBuffer(4);
const uint8Array1 = new Uint8Array(arrayBuffer1);
uint8Array1[0] = 1;
uint8Array1[1] = 2;
uint8Array1[2] = 3;
uint8Array1[3] = 4;
const arrayBuffer2 = new ArrayBuffer(2);
const uint8Array2 = new Uint8Array(arrayBuffer2);
uint8Array2[0] = 5;
uint8Array2[1] = 6;
let client = new CustomDataFetchClient();
const combinedArrayBuffer = client.combineArrayBuffers([arrayBuffer1, arrayBuffer2]);
expect(combinedArrayBuffer.byteLength).assertEqual(6);
const combinedUint8Array = new Uint8Array(combinedArrayBuffer);
for (let i = 0; i < 4; i++) {
expect(combinedUint8Array[i]).assertEqual(uint8Array1[i]);
}
for (let i = 0; i < 2; i++) {
expect(combinedUint8Array[i + 4]).assertEqual(uint8Array2[i]);
}
});
})
}

View File

@ -69,5 +69,3 @@ export { CropTransformation } from './src/main/ets/transform/CropTransformation'
export { MaskTransformation } from './src/main/ets/transform/MaskTransformation'
export { SepiaTransformation } from './src/main/ets/transform/SepiaTransformation'
export { DownsampleStrategy } from './src/main/ets/downsampling/DownsampleStartegy'

View File

@ -152,7 +152,7 @@ export class ImageKnife {
*/
preload(loadSrc:string | ImageKnifeOption):ImageKnifeRequest{
let imageKnifeOption = new ImageKnifeOption()
if (typeof loadSrc == "string") {
if (typeof loadSrc == 'string') {
imageKnifeOption.loadSrc = loadSrc
} else {
imageKnifeOption = loadSrc;
@ -186,15 +186,15 @@ export class ImageKnife {
preLoadCache(loadSrc: string | ImageKnifeOption): Promise<string> {
return new Promise((resolve, reject) => {
let imageKnifeOption = new ImageKnifeOption()
if (typeof loadSrc == "string") {
if (typeof loadSrc == 'string') {
imageKnifeOption.loadSrc = loadSrc
} else {
imageKnifeOption = loadSrc;
}
LogUtil.log("ImageKnife_DataTime_preLoadCache-imageKnifeOption:"+loadSrc)
LogUtil.log('ImageKnife_DataTime_preLoadCache-imageKnifeOption:'+loadSrc)
let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature)
let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey)
if (cachePath == null || cachePath == "" || cachePath == undefined) {
if (cachePath == null || cachePath == '' || cachePath == undefined) {
imageKnifeOption.onLoadListener = {
onLoadSuccess(){
resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey))
@ -317,14 +317,14 @@ export class ImageKnife {
}
loadFromMemoryCache(key: string): ImageKnifeData | undefined {
if (key !== "") {
if (key !== '') {
return this.memoryCache.get(key)
}
return undefined
}
saveMemoryCache(key: string, data: ImageKnifeData): void {
if (key !== "") {
if (key !== '') {
this.memoryCache.put(key, data)
}
}
@ -356,7 +356,7 @@ export class ImageKnife {
if (this.isFileCacheInit()) {
return this.fileCache?.maxMemory;
} else {
throw new Error("the disk cache not init");
throw new Error('the disk cache not init');
}
}
}
@ -376,7 +376,7 @@ export class ImageKnife {
if (this.isFileCacheInit()) {
return this.fileCache?.size();
} else {
throw new Error("the disk cache not init");
throw new Error('the disk cache not init');
}
}
}
@ -396,7 +396,7 @@ export class ImageKnife {
if (this.isFileCacheInit()) {
return this.fileCache?.currentMemory;
} else {
throw new Error("the disk cache not init");
throw new Error('the disk cache not init');
}
}
}
@ -424,7 +424,7 @@ export class ImageKnife {
if (typeValue === 'gif' || typeValue === 'webp') {
let base64Help = new util.Base64Helper()
let base64str = "data:image/" + typeValue + ";base64," + base64Help.encodeToStringSync(new Uint8Array(buffer))
let base64str = 'data:image/' + typeValue + ';base64,' + base64Help.encodeToStringSync(new Uint8Array(buffer))
onComplete({
source: base64str,
imageWidth: 0,
@ -463,12 +463,12 @@ export class ImageKnife {
}
async execute(request: ImageKnifeRequest,isAnimator?: boolean): Promise<void> {
LogUtil.log("ImageKnife_DataTime_execute.start:"+request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_execute.start:'+request.imageKnifeOption.loadSrc)
if (this.headerMap.size > 0) {
request.addHeaderMap(this.headerMap)
}
this.dispatcher.enqueue(request,isAnimator)
LogUtil.log("ImageKnife_DataTime_execute.end:"+request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_execute.end:'+request.imageKnifeOption.loadSrc)
}
setEngineKeyImpl(impl: IEngineKey): void {

View File

@ -49,7 +49,7 @@ export class ImageKnifeDispatcher {
private engineKey: IEngineKey = new DefaultEngineKey();
showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?: boolean): boolean {
LogUtil.log("ImageKnife_DataTime_showFromMemomry.start:" + request.imageKnifeOption.loadSrc + "requestSource=" + requestSource + " isAnimator=" + isAnimator)
LogUtil.log('ImageKnife_DataTime_showFromMemomry.start:' + request.imageKnifeOption.loadSrc + 'requestSource=' + requestSource + ' isAnimator=' + isAnimator)
let memoryCache: ImageKnifeData | undefined;
let memoryCheckStartTime = Date.now();
if ((typeof (request.imageKnifeOption.loadSrc as image.PixelMap).isEditable) == 'boolean') {
@ -82,12 +82,12 @@ export class ImageKnifeDispatcher {
// 回调请求开始
if (requestSource === ImageKnifeRequestSource.SRC && request.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) {
request.imageKnifeOption.onLoadListener.onLoadStart(request)
LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadStart:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_MemoryCache_onLoadStart:' + request.imageKnifeOption.loadSrc)
}
LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.start:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_MemoryCache_showPixelMap.start:' + request.imageKnifeOption.loadSrc)
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)
LogUtil.log('ImageKnife_DataTime_MemoryCache_showPixelMap.end:' + request.imageKnifeOption.loadSrc)
if (requestSource == ImageKnifeRequestSource.SRC) {
request.requestState = ImageKnifeRequestState.COMPLETE
@ -95,16 +95,16 @@ export class ImageKnifeDispatcher {
if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) {
this.copyMemoryCacheInfo(memoryCache, request.getImageKnifeData());
request.imageKnifeOption.onLoadListener.onLoadSuccess(memoryCache.source, memoryCache, request)
LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadSuccess:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_MemoryCache_onLoadSuccess:' + request.imageKnifeOption.loadSrc)
}
} else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) {
request.requestState = ImageKnifeRequestState.ERROR
}
}
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_hasmemory:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_showFromMemomry.end_hasmemory:' + request.imageKnifeOption.loadSrc)
return true
}
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_nomemory:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_showFromMemomry.end_nomemory:' + request.imageKnifeOption.loadSrc)
return false
}
@ -140,7 +140,7 @@ export class ImageKnifeDispatcher {
}
//图片加载信息回调数据
let callBackData: ImageKnifeData = {
source: "",
source: '',
imageWidth: 0,
imageHeight: 0,
};
@ -176,7 +176,7 @@ export class ImageKnifeDispatcher {
}
executeJob(request: ImageKnifeRequest,isAnimator?: boolean): void {
LogUtil.log("ImageKnife_DataTime_executeJob.start:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_executeJob.start:' + request.imageKnifeOption.loadSrc)
// 加载占位符
if (request.imageKnifeOption.placeholderSrc !== undefined && request.drawPlayHolderSuccess == false) {
this.getAndShowImage(request, request.imageKnifeOption.placeholderSrc, ImageKnifeRequestSource.PLACE_HOLDER)
@ -184,17 +184,17 @@ export class ImageKnifeDispatcher {
// 加载主图
this.getAndShowImage(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC,isAnimator)
LogUtil.log("ImageKnife_DataTime_executeJob.end:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_executeJob.end:' + request.imageKnifeOption.loadSrc)
}
/**
* 获取和显示图片
*/
getAndShowImage(currentRequest: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?: boolean): void {
LogUtil.log("ImageKnife_DataTime_getAndShowImage.start:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage.start:' + currentRequest.imageKnifeOption.loadSrc)
if (requestSource === ImageKnifeRequestSource.SRC && currentRequest.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) {
currentRequest.imageKnifeOption.onLoadListener?.onLoadStart(currentRequest)
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadStart:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_onLoadStart:' + currentRequest.imageKnifeOption.loadSrc)
}
let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption,isAnimator)
@ -217,22 +217,22 @@ export class ImageKnifeDispatcher {
requestList.forEach((requestWithSource: ImageKnifeRequestWithSource) => {
if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) {
requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadStart(requestWithSource.request)
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadStart:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_onLoadStart:' + currentRequest.imageKnifeOption.loadSrc)
}
if (requestWithSource.request.imageKnifeOption.progressListener !== undefined && requestWithSource.source === ImageKnifeRequestSource.SRC) {
isWatchProgress = true
}
});
let src: string | number = ""
let moduleName: string = ""
let resName: string = ""
let src: string | number = ''
let moduleName: string = ''
let resName: string = ''
if((imageSrc as Resource).id != undefined) {
moduleName = (imageSrc as Resource).moduleName
src = (imageSrc as Resource).id
if(src == -1) {
resName = (imageSrc as Resource).params![0]
}
} else if(typeof imageSrc == "string") {
} else if(typeof imageSrc == 'string') {
src = imageSrc
}
let request: RequestJobRequest = {
@ -254,8 +254,8 @@ export class ImageKnifeDispatcher {
memoryKey: memoryKey,
fileCacheFolder: ImageKnife.getInstance().getFileCache()?.getCacheFolder(),
isAnimator:isAnimator,
moduleName: moduleName == "" ? undefined : moduleName,
resName: resName == "" ? undefined : resName,
moduleName: moduleName == '' ? undefined : moduleName,
resName: resName == '' ? undefined : resName,
caPath: currentRequest.imageKnifeOption.caPath,
targetWidth: currentRequest.componentWidth,
targetHeight: currentRequest.componentHeight,
@ -272,32 +272,26 @@ export class ImageKnifeDispatcher {
if (isWatchProgress){
emitter.off(Constants.PROGRESS_EMITTER + memoryKey)
}
LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_execute.end:'+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage.end:'+currentRequest.imageKnifeOption.loadSrc)
})
if (ImageKnife.getInstance().isRequestInSubThread){
// 启动线程下载和解码主图
LogUtil.log("ImageKnife_DataTime_getAndShowImage_Task.start:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_Task.start:' + currentRequest.imageKnifeOption.loadSrc)
let task = new taskpool.Task(requestJob, request)
LogUtil.log("ImageKnife_DataTime_getAndShowImage_Task.end:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_Task.end:' + currentRequest.imageKnifeOption.loadSrc)
if (isWatchProgress){
emitter.on(Constants.PROGRESS_EMITTER + memoryKey, (data) => {
this.progressCallBack(requestList! , data?.data?.value as number)
});
}
LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.start(subthread):" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_execute.start(subthread):' + currentRequest.imageKnifeOption.loadSrc)
taskpool.execute(task).then((res: Object) => {
// this.doTaskCallback(res as RequestJobResult | undefined, requestList!, currentRequest, memoryKey, imageSrc, requestSource,isAnimator);
// if (isWatchProgress){
// emitter.off(Constants.PROGRESS_EMITTER + memoryKey)
// }
// LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.end:"+currentRequest.imageKnifeOption.loadSrc)
// LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:"+currentRequest.imageKnifeOption.loadSrc)
}).catch((err: BusinessError) => {
emitter.off(Constants.CALLBACK_EMITTER + memoryKey)
LogUtil.error("Fail to requestJob in sub thread src=" + imageSrc + " err=" + err)
LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.error('Fail to requestJob in sub thread src=' + imageSrc + ' err=' + err)
LogUtil.log('ImageKnife_DataTime_getAndShowImage.end:' + currentRequest.imageKnifeOption.loadSrc)
if (isWatchProgress){
emitter.off(Constants.PROGRESS_EMITTER + memoryKey)
}
@ -305,15 +299,12 @@ export class ImageKnifeDispatcher {
this.dispatchNextJob();
})
} else { //主线程请求
LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.start(mainthread):" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_execute.start(mainthread):' + currentRequest.imageKnifeOption.loadSrc)
requestJob(request, requestList).then(() => {
// this.doTaskCallback(res, requestList!, currentRequest, memoryKey, imageSrc, requestSource,isAnimator);
// LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.end:"+currentRequest.imageKnifeOption.loadSrc)
// LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:"+currentRequest.imageKnifeOption.loadSrc)
}).catch((err: BusinessError) => {
emitter.off(Constants.CALLBACK_EMITTER + memoryKey)
LogUtil.error("Fail to requestJob in main thread src=" + imageSrc + " err=" + err)
LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:" + currentRequest.imageKnifeOption.loadSrc)
LogUtil.error('Fail to requestJob in main thread src=' + imageSrc + ' err=' + err)
LogUtil.log('ImageKnife_DataTime_getAndShowImage.end:' + currentRequest.imageKnifeOption.loadSrc)
this.executingJobMap.remove(memoryKey);
this.dispatchNextJob();
})
@ -336,7 +327,7 @@ export class ImageKnifeDispatcher {
private doTaskCallback(requestJobResult: RequestJobResult | undefined, requestList: List<ImageKnifeRequestWithSource> ,
currentRequest: ImageKnifeRequest, memoryKey: string, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?: boolean):void {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.start:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_CallBack.start:'+currentRequest.imageKnifeOption.loadSrc)
if (requestJobResult === undefined){
return
}
@ -348,7 +339,7 @@ export class ImageKnifeDispatcher {
let pixelmap = requestJobResult.pixelMap;
if (pixelmap === undefined) {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.pixelmap undefined:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_CallBack.pixelmap undefined:'+currentRequest.imageKnifeOption.loadSrc)
requestList.forEach((requestWithSource: ImageKnifeRequestWithSource) => {
// 回调请求失败
if (requestWithSource.source === ImageKnifeRequestSource.SRC &&
@ -356,7 +347,7 @@ export class ImageKnifeDispatcher {
requestJobResult.loadFail) {
this.assembleImageKnifeData(requestWithSource.request.getImageKnifeData(), requestJobResult.imageKnifeData, requestWithSource.request)
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadFailed(requestJobResult.loadFail,requestWithSource.request);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadFailed:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_onLoadFailed:'+currentRequest.imageKnifeOption.loadSrc)
}
if (requestWithSource.source === ImageKnifeRequestSource.SRC &&
requestWithSource.request.imageKnifeOption.errorholderSrc !== undefined) {
@ -374,9 +365,9 @@ export class ImageKnifeDispatcher {
}
// 保存文件缓存
if (requestJobResult.bufferSize > 0 && currentRequest.imageKnifeOption.writeCacheStrategy !== CacheStrategy.Memory) {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.start:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.start:'+currentRequest.imageKnifeOption.loadSrc)
ImageKnife.getInstance().saveWithoutWriteFile(requestJobResult.fileKey, requestJobResult.bufferSize);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.end:'+currentRequest.imageKnifeOption.loadSrc)
}
let imageKnifeData: ImageKnifeData;
@ -414,11 +405,11 @@ export class ImageKnifeDispatcher {
// 保存内存缓存
if (currentRequest.imageKnifeOption.writeCacheStrategy !== CacheStrategy.File) {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.start:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_saveMemoryCache.start:'+currentRequest.imageKnifeOption.loadSrc)
ImageKnife.getInstance()
.saveMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption,isAnimator),
saveCacheImageData);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_saveMemoryCache.end:'+currentRequest.imageKnifeOption.loadSrc)
}
if (requestList !== undefined) {
// key相同的request一起绘制
@ -429,11 +420,11 @@ export class ImageKnifeDispatcher {
requestWithSource.source === ImageKnifeRequestSource.ERROR_HOLDER
|| (requestWithSource.source === ImageKnifeRequestSource.PLACE_HOLDER &&
requestWithSource.request.requestState === ImageKnifeRequestState.PROGRESS)) {
LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.start:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_showPixelMap.start:'+currentRequest.imageKnifeOption.loadSrc)
requestWithSource.request.ImageKnifeRequestCallback.showPixelMap(requestWithSource.request.componentVersion,
imageKnifeData.source, { width: imageKnifeData.imageWidth, height: imageKnifeData.imageHeight },
requestWithSource.source, imageKnifeData.imageAnimator);
LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_showPixelMap.end:'+currentRequest.imageKnifeOption.loadSrc)
}
if (requestWithSource.source == ImageKnifeRequestSource.SRC) {
@ -444,7 +435,7 @@ export class ImageKnifeDispatcher {
this.assembleImageKnifeData(requestWithSource.request.getImageKnifeData(), imageKnifeData,requestWithSource.request);
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(imageKnifeData.source,
saveCacheImageData, requestWithSource.request);
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) {
requestWithSource.request.requestState = ImageKnifeRequestState.ERROR;
@ -464,7 +455,7 @@ export class ImageKnifeDispatcher {
}
}
this.assembleImageKnifeData(callBackData,requestJobResult.imageKnifeData,requestWithSource.request)
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel("component has destroyed", requestWithSource.request)
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed', requestWithSource.request)
}
}
});
@ -472,24 +463,24 @@ export class ImageKnifeDispatcher {
this.executingJobMap.remove(memoryKey);
this.dispatchNextJob();
} else {
LogUtil.log("error: no requestlist need to draw for key = " + memoryKey);
LogUtil.log('error: no requestlist need to draw for key = ' + memoryKey);
}
LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.end:"+currentRequest.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_getAndShowImage_CallBack.end:'+currentRequest.imageKnifeOption.loadSrc)
}
dispatchNextJob() {
LogUtil.log("ImageKnife_DataTime_dispatchNextJob.start")
LogUtil.log('ImageKnife_DataTime_dispatchNextJob.start')
while (true) {
let request = this.jobQueue.pop()
if (request === undefined) {
LogUtil.log("ImageKnife_DataTime_dispatchNextJob.end:no any job")
LogUtil.log('ImageKnife_DataTime_dispatchNextJob.end:no any job')
break // 队列已无任务
}
else if (request.requestState === ImageKnifeRequestState.PROGRESS) {
LogUtil.log("ImageKnife_DataTime_dispatchNextJob.start executeJob:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_dispatchNextJob.start executeJob:' + request.imageKnifeOption.loadSrc)
this.executeJob(request)
LogUtil.log("ImageKnife_DataTime_dispatchNextJob.end executeJob:" + request.imageKnifeOption.loadSrc)
LogUtil.log('ImageKnife_DataTime_dispatchNextJob.end executeJob:' + request.imageKnifeOption.loadSrc)
break
}else if (request.requestState == ImageKnifeRequestState.DESTROY && request.imageKnifeOption.onLoadListener?.onLoadCancel) {
//构建回调错误信息
@ -504,7 +495,7 @@ export class ImageKnifeDispatcher {
};
callBackData.errorInfo = errorInfo;
}
request.imageKnifeOption.onLoadListener.onLoadCancel("component has destroyed", request)
request.imageKnifeOption.onLoadListener.onLoadCancel('component has destroyed', request)
}
}
}
@ -532,8 +523,8 @@ export class ImageKnifeDispatcher {
*/
@Concurrent
async function requestJob(request: RequestJobRequest, requestList?: List<ImageKnifeRequestWithSource>) {
LogUtil.log("ImageKnife_DataTime_requestJob.start:" + request.src + " requestSource=" + request.requestSource)
let src = typeof request.src == "number" ? request.resName != undefined ? request.resName : request.src + "" : request.src
LogUtil.log('ImageKnife_DataTime_requestJob.start:' + request.src + ' requestSource=' + request.requestSource)
let src = typeof request.src == 'number' ? request.resName != undefined ? request.resName : request.src + '' : request.src
// 生成文件缓存key
let fileKey = request.engineKey.generateFileKey(src, request.signature, request.isAnimator)

View File

@ -53,8 +53,8 @@ export class ImageKnifeLoader {
callBackData.bufSize = resBuf.byteLength;
let typeValue = new FileTypeUtil().getFileType(resBuf);
if(typeValue == null) {
LogUtil.log("ImageKnife_DataTime_requestJob.end: getFileType is null " + request.src)
ImageKnifeLoader.makeEmptyResult(request,"request is not a valid image source", ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_GET_FORMAT, LoadPixelMapCode.IMAGE_PARSE_FORMAT_FAILED_CODE))
LogUtil.log('ImageKnife_DataTime_requestJob.end: getFileType is null ' + request.src)
ImageKnifeLoader.makeEmptyResult(request,'request is not a valid image source', ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_GET_FORMAT, LoadPixelMapCode.IMAGE_PARSE_FORMAT_FAILED_CODE))
return
}
callBackData.type = typeValue;
@ -66,7 +66,7 @@ export class ImageKnifeLoader {
if (typeValue === 'gif' || typeValue === 'webp') {
ImageKnifeLoader.parseAnimatorImage(resBuf ,typeValue ,fileKey , request, callBackData)
return
} else if(typeValue == "svg") {
} else if(typeValue == 'svg') {
ImageKnifeLoader.parseSvgImage(resBuf ,typeValue ,fileKey , request, callBackData)
return
}
@ -82,7 +82,7 @@ export class ImageKnifeLoader {
loadFail: error,
imageKnifeData: data
}
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { "value": res } })
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
}
static assembleError(data: ImageKnifeData | undefined, phase: string, code?: number,
@ -119,7 +119,7 @@ export class ImageKnifeLoader {
}
let imageSource: image.ImageSource = image.createImageSource(resBuf)
if (imageSource === undefined){
ImageKnifeLoader.makeEmptyResult(request,"image.createImageSource failed", ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
ImageKnifeLoader.makeEmptyResult(request,'image.createImageSource failed', ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
return
}
@ -150,19 +150,19 @@ export class ImageKnifeLoader {
return
})
if (request.requestSource === ImageKnifeRequestSource.SRC && request.transformation !== undefined && resPixelmap !== undefined) {
LogUtil.log("ImageKnife_DataTime_requestJob.transform.start:" + request.src)
LogUtil.log('ImageKnife_DataTime_requestJob.transform.start:' + request.src)
resPixelmap = await request.transformation?.transform(request.context, resPixelmap, request.componentWidth, request.componentHeight);
LogUtil.log("ImageKnife_DataTime_requestJob.transform.end:" + request.src)
LogUtil.log('ImageKnife_DataTime_requestJob.transform.end:' + request.src)
}
try {
resPixelmap?.setTransferDetached(true)
} catch (e) {
LogUtil.error("PixelMap setTransferDetached err:"+JSON.stringify(e))
LogUtil.error('PixelMap setTransferDetached err:'+JSON.stringify(e))
}
//获取各个pixelMap的大小
if (resPixelmap && typeof resPixelmap !== "string") {
let decodeImages: Array<DecodeImageInfo> = [];
if (resPixelmap && typeof resPixelmap !== 'string') {
let decodeImages: DecodeImageInfo[] = [];
let size = (resPixelmap as PixelMap).getImageInfoSync().size;
let decodeImage: DecodeImageInfo = {
contentWidth: size.width,
@ -181,7 +181,7 @@ export class ImageKnifeLoader {
type:typeValue,
imageKnifeData:callBackData
}
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { "value": res } })
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
}
static async parseSvgImage(resBuf: ArrayBuffer, typeValue: string, fileKey: string,
request: RequestJobRequest, callBackData: ImageKnifeData) {
@ -190,7 +190,7 @@ export class ImageKnifeLoader {
let imageSource: image.ImageSource = image.createImageSource(resBuf)
if (imageSource === undefined){
ImageKnifeLoader.makeEmptyResult(request,"image.createImageSource failed", ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
ImageKnifeLoader.makeEmptyResult(request,'image.createImageSource failed', ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
return
}
@ -226,7 +226,7 @@ export class ImageKnifeLoader {
try {
resPixelmap.setTransferDetached(true)
} catch (e) {
LogUtil.error("PixelMap setTransferDetached err:"+JSON.stringify(e))
LogUtil.error('PixelMap setTransferDetached err:'+JSON.stringify(e))
}
}).catch((error: BusinessError) => {
timeInfo.decodeEndTime = Date.now();
@ -236,8 +236,8 @@ export class ImageKnifeLoader {
})
//获取各个pixelMap的大小
if (resPixelmap && typeof resPixelmap !== "string") {
let decodeImages: Array<DecodeImageInfo> = [];
if (resPixelmap && typeof resPixelmap !== 'string') {
let decodeImages: DecodeImageInfo[] = [];
let decodeImage: DecodeImageInfo = {
contentWidth: defaultSize.width,
contentHeight: defaultSize.height,
@ -253,14 +253,14 @@ export class ImageKnifeLoader {
type:typeValue,
imageKnifeData:callBackData
}
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { "value": res } })
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
}
static async parseAnimatorImage(resBuf: ArrayBuffer, typeValue: string,
fileKey: string,request: RequestJobRequest, callBackData: ImageKnifeData) {
let timeInfo: TimeInfo = ImageKnifeLoader.getTimeInfo(callBackData);
let imageSource: image.ImageSource = image.createImageSource(resBuf)
if (imageSource === undefined){
ImageKnifeLoader.makeEmptyResult(request,"image.createImageSource failed", ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_CREATE_SOURCE,LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
ImageKnifeLoader.makeEmptyResult(request,'image.createImageSource failed', ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_CREATE_SOURCE,LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
return
}
@ -275,7 +275,7 @@ export class ImageKnifeLoader {
if(frameCount == undefined || frameCount == 1) {
} else {
timeInfo.decodeStartTime = Date.now()
let base64str = "data:image/" + typeValue + ";base64," + new util.Base64Helper().encodeToStringSync(new Uint8Array(resBuf))
let base64str = 'data:image/' + typeValue + ';base64,' + new util.Base64Helper().encodeToStringSync(new Uint8Array(resBuf))
timeInfo.diskCheckEndTime = Date.now()
let res: RequestJobResult = {
pixelMap: base64str,
@ -285,7 +285,7 @@ export class ImageKnifeLoader {
type:typeValue,
imageKnifeData:callBackData
}
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { "value": res } })
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
return
}
ImageKnifeLoader.parseNormalImage(resBuf, typeValue, fileKey, request, callBackData)
@ -297,7 +297,7 @@ export class ImageKnifeLoader {
if (typeValue === 'gif' || typeValue === 'webp') {
let imageSource: image.ImageSource = image.createImageSource(resBuf);
if (imageSource === undefined){
ImageKnifeLoader.makeEmptyResult(request,"image.createImageSource failed", ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
ImageKnifeLoader.makeEmptyResult(request,'image.createImageSource failed', ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CREATE_SOURCE, LoadPixelMapCode.IMAGE_SOURCE_ERROR_CODE))
return
}
let decodingOptions: image.DecodingOptions = {
@ -341,7 +341,7 @@ export class ImageKnifeLoader {
})
callBackData.decodeImages = decodeImages;
let res: RequestJobResult = {
pixelMap: "",
pixelMap: '',
bufferSize: resBuf.byteLength,
fileKey: fileKey,
type: typeValue,
@ -349,9 +349,9 @@ export class ImageKnifeLoader {
pixelMapList,
delayList
}
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { "value": res } })
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
} else {
ImageKnifeLoader.makeEmptyResult(request,"ImageKnifeAnimatorComponent组件仅支持动态图", ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_PARSE_IAMGE,LoadPixelMapCode.IMAGE_FORMAT_ERROR_CODE))
ImageKnifeLoader.makeEmptyResult(request,'ImageKnifeAnimatorComponent组件仅支持动态图', ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_PARSE_IAMGE,LoadPixelMapCode.IMAGE_FORMAT_ERROR_CODE))
}
}
static getHeaderObj(request:RequestJobRequest){
@ -370,23 +370,23 @@ export class ImageKnifeLoader {
static FileCacheParseImage(request:RequestJobRequest,resBuf:ArrayBuffer,fileKey:string, callBackData: ImageKnifeData){
// 保存文件缓存
if (resBuf !== undefined && request.writeCacheStrategy !== CacheStrategy.Memory) {
LogUtil.log("ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.start:"+request.src)
LogUtil.log('ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.start:'+request.src)
FileCache.saveFileCacheOnlyFile(request.context, fileKey, resBuf , request.fileCacheFolder)
LogUtil.log("ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.end:"+request.src)
LogUtil.log('ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.end:'+request.src)
}
ImageKnifeLoader.parseImage(resBuf,fileKey,request, callBackData)
}
// 获取图片资源
static async getImageArrayBuffer(request: RequestJobRequest, requestList: List<ImageKnifeRequestWithSource> | undefined,fileKey:string) {
let resBuf: ArrayBuffer | undefined
let loadError: string = ""
let loadError: string = ''
//定义图片各个阶段错误信息
let error: ErrorInfo = { code: 0, phase: LoadPhase.PHASE_LOAD }
//定义加载时间点
let callBackTimeInfo: TimeInfo = {};
//定义加载信息回调数据
let callBackData: ImageKnifeData = {
source: "",
source: '',
imageWidth: 0,
imageHeight: 0,
timeInfo: callBackTimeInfo,
@ -394,14 +394,14 @@ export class ImageKnifeLoader {
};
// 判断自定义下载
if (request.customGetImage !== undefined && request.requestSource == ImageKnifeRequestSource.SRC && typeof request.src == "string") {
if (request.customGetImage !== undefined && request.requestSource == ImageKnifeRequestSource.SRC && typeof request.src == 'string') {
// 先从文件缓存获取
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_CUSTOM_LOAD)
callBackTimeInfo.diskCheckStartTime = Date.now();
resBuf = FileCache.getFileCacheByFile(request.context, fileKey , request.fileCacheFolder)
callBackTimeInfo.diskCheckEndTime = Date.now();
if (resBuf === undefined) {
LogUtil.log("start customGetImage src=" + request.src)
LogUtil.log('start customGetImage src=' + request.src)
const headerObj: Record<string, Object> = ImageKnifeLoader.getHeaderObj(request)
try {
request.customGetImage(request.context, request.src, headerObj)
@ -409,39 +409,39 @@ export class ImageKnifeLoader {
if(buffer != undefined) {
ImageKnifeLoader.FileCacheParseImage(request,buffer,fileKey,callBackData)
} else {
loadError = "customGetImage loadFail undefined"
loadError = 'customGetImage loadFail undefined'
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CUSTOM_LOAD, LoadPixelMapCode.IMAGE_CUSTOM_LOAD_FAILED_CODE))
}
}).catch((err:string)=>{
ImageKnifeLoader.makeEmptyResult(request,err, ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CUSTOM_LOAD, LoadPixelMapCode.IMAGE_CUSTOM_LOAD_FAILED_CODE))
})
} catch (e) {
loadError = "customGetImage loadFail failed"
loadError = 'customGetImage loadFail failed'
ImageKnifeLoader.makeEmptyResult(request,loadError + e, ImageKnifeLoader.assembleError(callBackData, LoadPhase.PHASE_CUSTOM_LOAD, LoadPixelMapCode.IMAGE_CUSTOM_LOAD_FAILED_CODE))
}
LogUtil.log("end customGetImage src=" + request.src)
LogUtil.log('end customGetImage src=' + request.src)
return
}
}
else {
if (typeof request.src === 'string') {
if (request.src.indexOf("http://") == 0 || request.src.indexOf("https://") == 0) { //从网络下载
if (request.src.indexOf('http://') == 0 || request.src.indexOf('https://') == 0) { //从网络下载
// 先从文件缓存获取
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET)
callBackTimeInfo.diskCheckStartTime = Date.now()
resBuf = FileCache.getFileCacheByFile(request.context, fileKey , request.fileCacheFolder)
callBackTimeInfo.diskCheckEndTime = Date.now()
if (resBuf !== undefined){
LogUtil.log("success get image from filecache for key = " + fileKey + " src = " + request.src)
LogUtil.log('success get image from filecache for key = ' + fileKey + ' src = ' + request.src)
}
else if (request.onlyRetrieveFromCache != true) {
LogUtil.log("HttpDownloadClient.start:" + request.src)
LogUtil.log('HttpDownloadClient.start:' + request.src)
callBackTimeInfo.netRequestStartTime = Date.now();
let httpRequest = http.createHttp();
let progress: number = 0
let arrayBuffers = new Array<ArrayBuffer>()
let arrayBuffers:ArrayBuffer[] = []
const headerObj: Record<string, Object> = ImageKnifeLoader.getHeaderObj(request)
httpRequest.on("dataReceive", (data: ArrayBuffer) => {
httpRequest.on('dataReceive', (data: ArrayBuffer) => {
arrayBuffers.push(data)
});
@ -454,7 +454,7 @@ export class ImageKnifeLoader {
progress = percent
if (requestList === undefined) {
// 子线程
emitter.emit(Constants.PROGRESS_EMITTER + request.memoryKey, { data: { "value": progress } })
emitter.emit(Constants.PROGRESS_EMITTER + request.memoryKey, { data: { 'value': progress } })
}else {
// 主线程请求
requestList!.forEach((requestWithSource: ImageKnifeRequestWithSource) => {
@ -485,15 +485,15 @@ export class ImageKnifeLoader {
resBuf = combineArrayBuffers(arrayBuffers)
ImageKnifeLoader.FileCacheParseImage(request,resBuf,fileKey, callBackData)
} else {
loadError = "HttpDownloadClient has error, http code =" + JSON.stringify(data)
loadError = 'HttpDownloadClient has error, http code =' + JSON.stringify(data)
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE, data))
}
}).catch((err: Error) => {
loadError = "HttpDownloadClient download ERROR : err = " + JSON.stringify(err)
loadError = 'HttpDownloadClient download ERROR : err = ' + JSON.stringify(err)
callBackTimeInfo.netRequestEndTime = Date.now();
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE, undefined))
});
LogUtil.log("HttpDownloadClient.end:" + request.src)
LogUtil.log('HttpDownloadClient.end:' + request.src)
return
}
else {
@ -510,15 +510,15 @@ export class ImageKnifeLoader {
fs.closeSync(file.fd);
}).catch((err:BusinessError) => {
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_SHARE_FILE, LoadPixelMapCode.IMAGE_LOAD_SHARE_FILE_FAILED_CODE)
loadError = 'LoadDataShareFileClient fs.read err happened uri=' + request.src + " err.msg=" + err?.message + " err.code=" + err?.code
loadError = 'LoadDataShareFileClient fs.read err happened uri=' + request.src + ' err.msg=' + err?.message + ' err.code=' + err?.code
})
}).catch((err:BusinessError) => {
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_SHARE_FILE, LoadPixelMapCode.IMAGE_LOAD_SHARE_FILE_FAILED_CODE)
loadError = 'LoadDataShareFileClient fs.stat err happened uri=' + request.src + " err.msg=" + err?.message + " err.code=" + err?.code
loadError = 'LoadDataShareFileClient fs.stat err happened uri=' + request.src + ' err.msg=' + err?.message + ' err.code=' + err?.code
})
}).catch((err:BusinessError) => {
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_SHARE_FILE, LoadPixelMapCode.IMAGE_LOAD_SHARE_FILE_FAILED_CODE)
loadError = 'LoadDataShareFileClient fs.open err happened uri=' + request.src + " err.msg=" + err?.message + " err.code=" + err?.code
loadError = 'LoadDataShareFileClient fs.open err happened uri=' + request.src + ' err.msg=' + err?.message + ' err.code=' + err?.code
})
} else { //从本地文件获取
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_LOCAL_FILE)
@ -535,7 +535,7 @@ export class ImageKnifeLoader {
loadError = err
}
}
} else if (typeof request.src == "number") { //从资源文件获取
} else if (typeof request.src == 'number') { //从资源文件获取
let manager = request.context.createModuleContext(request.moduleName).resourceManager
if (resBuf == undefined && request.onlyRetrieveFromCache != true && request.requestSource == ImageKnifeRequestSource.SRC) {
if(request.src == -1) {
@ -568,7 +568,7 @@ export class ImageKnifeLoader {
let reqSize =
new Downsampler().calculateScaling(typeValue, size.width, size.height, request.targetWidth, request.targetHeight,
request.downsampType)
if (typeValue == "svg") {
if (typeValue == 'svg') {
return {
editable: true,
desiredSize: {

View File

@ -25,11 +25,11 @@ const INT_MAX = 2147483647
* 子线程直接读写文件
*/
export class FileCache {
static CACHE_FOLDER: string = "ImageKnife" // context cacheDir 的缓存文件目录
static CACHE_FOLDER: string = 'ImageKnife' // context cacheDir 的缓存文件目录
maxMemory: number = 0
currentMemory: number = 0
maxSize: number = 0
path: string = ""
path: string = ''
private lruCache: util.LRUCache<string, number>
private isInited: boolean = false
private context?: Context
@ -153,11 +153,11 @@ export class FileCache {
this.remove(this.lruCache.keys()[0])
} else if (this.lruCache.contains(key)) {
this.lruCache.remove(key)
this.lruCache.put(key, typeof value == "number" ? value : value.byteLength)
this.lruCache.put(key, typeof value == 'number' ? value : value.byteLength)
return
}
this.lruCache.put(key, typeof value == "number" ? value : value.byteLength)
this.lruCache.put(key, typeof value == 'number' ? value : value.byteLength)
this.addMemorySize(value)
this.trimToSize()
}
@ -227,23 +227,23 @@ export class FileCache {
}
private removeMemorySize(value: ArrayBuffer | number): void {
if (typeof value == "number") {
if (typeof value == 'number') {
this.currentMemory -= value
}
else if (value != undefined) {
this.currentMemory -= value.byteLength
LogUtil.debug("FileCache removeMemorySize: " + value.byteLength + " currentMemory" + this.currentMemory)
LogUtil.debug('FileCache removeMemorySize: ' + value.byteLength + ' currentMemory' + this.currentMemory)
}
}
private addMemorySize(value: ArrayBuffer | number): void {
if (typeof value == "number") {
if (typeof value == 'number') {
this.currentMemory += value
LogUtil.debug("FileCache addMemorySize: " + value + " currentMemory" + this.currentMemory)
LogUtil.debug('FileCache addMemorySize: ' + value + ' currentMemory' + this.currentMemory)
}
else if (value != undefined) {
this.currentMemory += value.byteLength
LogUtil.debug("FileCache addMemorySize: " + value.byteLength + " currentMemory" + this.currentMemory)
LogUtil.debug('FileCache addMemorySize: ' + value.byteLength + ' currentMemory' + this.currentMemory)
}
}
@ -279,13 +279,13 @@ export class FileCache {
*/
getFileToPath(key: string): string {
if(!!!key) {
throw new Error("key is null,checking the parameter")
throw new Error('key is null,checking the parameter')
}
let path = this.path + key
if(FileUtils.getInstance().exist(path)) {
return path
} else {
return ""
return ''
}
}
}

View File

@ -106,9 +106,9 @@ export class MemoryLruCache implements IMemoryCache {
private removeMemorySize(value: ImageKnifeData): void {
if (value.source != undefined) {
if (typeof value.source === 'string' && value.source != "") {
if (typeof value.source === 'string' && value.source != '') {
this.currentMemory -= value.source.length
} else if (value.source == "") {
} else if (value.source == '') {
for (let index = 0;index < value.imageAnimator!.length;index++) {
let pixelMap = value.imageAnimator![index].src as PixelMap
this.currentMemory -= pixelMap.getPixelBytesNumber()
@ -117,15 +117,15 @@ export class MemoryLruCache implements IMemoryCache {
this.currentMemory -= value.source.getPixelBytesNumber();
value.source.release()
}
// LogUtil.info("MemoryCache removeMemorySize: " + value.source.getPixelBytesNumber() + " currentMemory" + this.currentMemory)
// LogUtil.info('MemoryCache removeMemorySize: ' + value.source.getPixelBytesNumber() + ' currentMemory' + this.currentMemory)
}
}
private getImageKnifeDataSize(value: ImageKnifeData): number {
if (value.source != undefined) {
if (typeof value.source === 'string' && value.source != "") {
if (typeof value.source === 'string' && value.source != '') {
return value.source.length
} else if (value.source == "") {
} else if (value.source == '') {
let size: number = 0
for (let index = 0; index < value.imageAnimator!.length; index++) {
let pixelMap = value.imageAnimator![index].src as PixelMap

View File

@ -74,7 +74,7 @@ export struct ImageKnifeAnimatorComponent {
} else {
// 前提:宽高值均有效,值>0. 条件1当前宽高与上一次宽高不同 条件2:当前是第一次绘制
if (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) {
LogUtil.log("execute request:width=" + this.currentWidth + " height= " + this.currentHeight)
LogUtil.log('execute request:width=' + this.currentWidth + ' height= ' + this.currentHeight)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight),true)
}
}

View File

@ -45,18 +45,18 @@ export struct ImageKnifeComponent {
let memoryCacheSrc: ImageKnifeData | undefined = ImageKnife.getInstance()
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,this.imageKnifeOption))
if (memoryCacheSrc !== undefined){
LogUtil.log("aboutToAppear success load loadSrc from memory cache for loadSrc = "+ this.imageKnifeOption.loadSrc)
LogUtil.log('aboutToAppear success load loadSrc from memory cache for loadSrc = '+ this.imageKnifeOption.loadSrc)
this.pixelMap = memoryCacheSrc.source;
}else{
LogUtil.log("aboutToAppear fail load loadSrc from memory cache for loadSrc = "+ this.imageKnifeOption.loadSrc)
LogUtil.log('aboutToAppear fail load loadSrc from memory cache for loadSrc = '+ this.imageKnifeOption.loadSrc)
if (this.imageKnifeOption.placeholderSrc !== undefined){
let memoryCachePlace: ImageKnifeData | undefined = ImageKnife.getInstance()
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.placeholderSrc!,ImageKnifeRequestSource.PLACE_HOLDER,this.imageKnifeOption))
if (memoryCachePlace !== undefined){
LogUtil.log("aboutToAppear success load placeholderSrc from memory cache for placeholderSrc = " + this.imageKnifeOption.placeholderSrc)
LogUtil.log('aboutToAppear success load placeholderSrc from memory cache for placeholderSrc = ' + this.imageKnifeOption.placeholderSrc)
this.pixelMap = memoryCachePlace.source;
}else{
LogUtil.log("aboutToAppear fail load placeholderSrc from memory cache for placeholderSrc = " + this.imageKnifeOption.placeholderSrc)
LogUtil.log('aboutToAppear fail load placeholderSrc from memory cache for placeholderSrc = ' + this.imageKnifeOption.placeholderSrc)
}
}
}
@ -100,7 +100,7 @@ export struct ImageKnifeComponent {
} else {
// 前提:宽高值均有效,值>0. 条件1当前宽高与上一次宽高不同 条件2:当前是第一次绘制
if (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) {
LogUtil.log("execute request:width=" + this.currentWidth + " height= " + this.currentHeight)
LogUtil.log('execute request:width=' + this.currentWidth + ' height= ' + this.currentHeight)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
}
}
@ -111,10 +111,10 @@ export struct ImageKnifeComponent {
this.clearLastRequest()
this.componentVersion++
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
LogUtil.log("watchImageKnifeOption execute request:width=" + this.currentWidth + " height= " + this.currentHeight
+ " loadSrc = " + this.request?.imageKnifeOption.loadSrc
+ " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
+ " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
LogUtil.log('watchImageKnifeOption execute request:width=' + this.currentWidth + ' height= ' + this.currentHeight
+ ' loadSrc = ' + this.request?.imageKnifeOption.loadSrc
+ ' placeholderSrc = ' + this.request?.imageKnifeOption.placeholderSrc
+ ' errorholderSrc = ' + this.request?.imageKnifeOption.errorholderSrc)
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
}
@ -141,21 +141,9 @@ export struct ImageKnifeComponent {
this.pixelMap = pixelMap
if (typeof this.pixelMap !== 'string') {
if (this.imageKnifeOption.objectFit === ImageFit.Auto) {
this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = size.height * this.currentWidth / size.width
// if (this.currentWidth / this.currentHeight > info.size.width / info.size.height) {
// this.adaptiveWidth = this.currentWidth
// this.adaptiveHeight = info.size.height * this.currentWidth / this.currentHeight
// }
// else {
// this.adaptiveWidth = info.size.width * this.currentWidth / this.currentHeight
// this.adaptiveHeight = this.currentHeight
// }
}
} else {
//console.info("KKKKKKKKKKK:" + pixelMap)
}
if (requestSource == ImageKnifeRequestSource.SRC) {

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -17,7 +17,7 @@ import { getScale, highestOneBit, round, SampleSizeRounding } from './Downsample
export class FitCenter implements BaseDownsampling {
getName() {
return "FitCenter"
return 'FitCenter'
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
@ -46,7 +46,7 @@ export class FitCenter implements BaseDownsampling {
export class AtLeast implements BaseDownsampling {
getName() {
return "AtLeast"
return 'AtLeast'
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number): number {
@ -67,7 +67,7 @@ export class AtLeast implements BaseDownsampling {
export class AtMost implements BaseDownsampling {
getName() {
return "AtMost"
return 'AtMost'
}
@ -96,7 +96,7 @@ export class AtMost implements BaseDownsampling {
然后再更据原图的缩放比去适配另一边*/
export class CenterInside implements BaseDownsampling {
getName() {
return "CenterInside"
return 'CenterInside'
}
getScaleFactor(sourceWidth: number, sourceHeight: number, requestedWidth: number, requestedHeight: number,
downsampType: DownsampleStrategy

View File

@ -36,12 +36,12 @@ export class Downsampler {
let scaleFactor: number =
downsampler.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType);//缩放比
//基于上一步得出的采样大小,根据不同的图片类型,计算采样后的图片尺寸
if (typeValue === "png") {
if (typeValue === 'png') {
return {
width: Math.floor(sourceWidth / scaleFactor),
height: Math.floor(sourceHeight / scaleFactor)
}
} else if (typeValue === "webp") {
} else if (typeValue === 'webp') {
return {
width: Math.round(sourceWidth / scaleFactor),
height: Math.round(sourceHeight / scaleFactor)

View File

@ -24,16 +24,16 @@ export class DefaultEngineKey implements IEngineKey {
// 生成内存缓存key
generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,
imageKnifeOption: ImageKnifeOption,isAnimator?: boolean, width?: number, height?: number): string {
let key = (isAnimator == true ? "Animator=" : "loadSrc==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
let key = (isAnimator == true ? 'Animator=' : 'loadSrc==') + (typeof loadSrc == 'string' ? loadSrc : JSON.stringify(loadSrc)) + ';'
if (requestSource === ImageKnifeRequestSource.SRC) {
if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") {
key += "signature=" + imageKnifeOption.signature + ";"
if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== '') {
key += 'signature=' + imageKnifeOption.signature + ';'
}
if (imageKnifeOption.transformation) {
key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";"
key += 'transformation=' + this.getTransformation(imageKnifeOption.transformation) + ';'
}
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
key += "downsampleOf" + imageKnifeOption.downsampleOf + "width=" + width + "height=" + height
key += 'downsampleOf' + imageKnifeOption.downsampleOf + 'width=' + width + 'height=' + height
}
}
return key
@ -41,9 +41,9 @@ export class DefaultEngineKey implements IEngineKey {
// 生成文件缓存key
generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string,isAnimator?: boolean): string {
let src = (isAnimator == true ? "Animator=" : "loadSrc==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
if (signature !== undefined && signature !== "") {
src += "signature=" + signature + ";"
let src = (isAnimator == true ? 'Animator=' : 'loadSrc==') + (typeof loadSrc == 'string' ? loadSrc : JSON.stringify(loadSrc)) + ';'
if (signature !== undefined && signature !== '') {
src += 'signature=' + signature + ';'
}
return SparkMD5.hashBinary(src)
}

View File

@ -52,7 +52,7 @@ interface ImageOption {
@Observed
export class ImageKnifeOption {
// 主图资源
loadSrc: string | PixelMap | Resource = "";
loadSrc: string | PixelMap | Resource = '';
// 占位图
placeholderSrc?: string | PixelMap | Resource;
// 失败占位图

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -44,7 +44,7 @@ export class CropCircleTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("CropCircleTransformation The image size does not exist.");
console.error('CropCircleTransformation The image size does not exist.');
return data;
}
let height: number = size.height;

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -67,7 +67,7 @@ export class CropCircleWithBorderTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("CropCircleWithBorderTransformation The image size does not exist.");
console.error('CropCircleWithBorderTransformation The image size does not exist.');
return pixelMap;
}
let height: number = size.height;

View File

@ -32,7 +32,7 @@ export class CropSquareTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("CropSquareTransformation The image size does not exist.");
console.error('CropSquareTransformation The image size does not exist.');
return toTransform;
}
let pixelMapWidth: number = size.width;

View File

@ -33,7 +33,7 @@ export class CropTransformation extends PixelMapTransformation {
}
getName(): string {
return this.constructor.name + ";mWidth:" + this.mWidth + ";mHeight:" + this.mHeight + ";mCropType:" + this.mCropType;
return this.constructor.name + ';mWidth:' + this.mWidth + ';mHeight:' + this.mHeight + ';mCropType:' + this.mCropType;
}
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
@ -43,7 +43,7 @@ export class CropTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("CropTransformation The image size does not exist.");
console.error('CropTransformation The image size does not exist.');
return toTransform;
}
let pixelMapWidth: number = size.width;

View File

@ -35,7 +35,7 @@ export class KuwaharaTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("KuwaharaTransformation The image size does not exist.");
console.error('KuwaharaTransformation The image size does not exist.');
return toTransform;
}
return await this.kuwaharaGpu(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -45,7 +45,7 @@ export class MaskTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("MaskTransformation The image size does not exist.");
console.error('MaskTransformation The image size does not exist.');
return toTransform;
}
let pixelMapWidth: number = size.width;
@ -62,17 +62,17 @@ export class MaskTransformation extends PixelMapTransformation {
private async openInternal(context: Context, bitmap: PixelMap, width: number, height: number): Promise<PixelMap> {
if (context == undefined) {
console.error("MaskTransformation openInternal the context is undefined.");
console.error('MaskTransformation openInternal the context is undefined.');
return bitmap;
}
let moduleContext = context.createModuleContext(this.mResourceModuleName);
if (moduleContext == undefined) {
console.error("MaskTransformation openInternal the moduleContext is undefined.");
console.error('MaskTransformation openInternal the moduleContext is undefined.');
return bitmap;
}
let resourceManager = moduleContext.resourceManager as resourceManager.ResourceManager;
if (resourceManager == undefined) {
console.error("MaskTransformation openInternal the resourceManager is undefined.");
console.error('MaskTransformation openInternal the resourceManager is undefined.');
return bitmap;
}
let array: Uint8Array = await resourceManager.getMediaContent(this.mResourceId);
@ -96,7 +96,7 @@ export class MaskTransformation extends PixelMapTransformation {
height: imageInfo.size.height
};
if (!size) {
console.error("MaskTransformation mask the image size does not exist.");
console.error('MaskTransformation mask the image size does not exist.');
return bitmap;
}
let width = size.width;
@ -133,7 +133,7 @@ export class MaskTransformation extends PixelMapTransformation {
height: imageInfoMask.size.height
};
if (!sizeMask) {
console.error("MaskTransformation mask the sizeMask size does not exist.");
console.error('MaskTransformation mask the sizeMask size does not exist.');
return bitmap;
}
let widthMask = sizeMask.width;

View File

@ -37,9 +37,9 @@ export class MultiTransTransformation extends PixelMapTransformation {
}
getName(): string {
let res: string = ""
let res: string = ''
this.transformations.forEach((transformation) => {
res += transformation.getName() + "&"
res += transformation.getName() + '&'
})
return res
}

View File

@ -39,7 +39,7 @@ export class PixelationTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("PixelationTransformation The image size does not exist.");
console.error('PixelationTransformation The image size does not exist.');
return toTransform;
}
return await this.pixelGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -28,7 +28,7 @@ export class SepiaTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("SepiaTransformation The image size does not exist.");
console.error('SepiaTransformation The image size does not exist.');
return toTransform;
}
return await this.sepiaGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -28,7 +28,7 @@ export class SketchTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("SketchTransformation The image size does not exist.");
console.error('SketchTransformation The image size does not exist.');
return toTransform;
}
return await this.sketchGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -50,7 +50,7 @@ export class SwirlTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("SwirlTransformation The image size does not exist.");
console.error('SwirlTransformation The image size does not exist.');
return toTransform;
}
return await this.swirlGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -41,7 +41,7 @@ export class ToonTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("ToonTransformation The image size does not exist.");
console.error('ToonTransformation The image size does not exist.');
return toTransform;
}
return await this.toonGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -54,7 +54,7 @@ export class VignetterTransformation extends PixelMapTransformation {
async transform(context: Context, toTransform: PixelMap, width: number, height: number): Promise<PixelMap> {
let imageInfo: image.ImageInfo = await toTransform.getImageInfo();
if (!imageInfo.size) {
console.error("VignetterTransformation The image size does not exist.");
console.error('VignetterTransformation The image size does not exist.');
return toTransform;
}
return await this.swirlGPU(toTransform, imageInfo.size.width, imageInfo.size.height);

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.
@ -21,6 +21,6 @@ export class PixelEntry {
pixel: number = 0;
public toString(): string {
return "PixelEntry a:" + this.a + ";b:" + this.b + ";r:" + this.r + ";g:" + this.g + ";f:" + this.f;
return 'PixelEntry a:' + this.a + ';b:' + this.b + ';r:' + this.r + ';g:' + this.g + ';f:' + this.f;
}
}

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.

View File

@ -1,13 +1,13 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* 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,
* 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.

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
export class Constants {
public static PROGRESS_EMITTER: string = "progressEmitter"
public static CALLBACK_EMITTER: string = "callBackEmitter"
public static PROGRESS_EMITTER: string = 'progressEmitter'
public static CALLBACK_EMITTER: string = 'callBackEmitter'
}
/**
@ -50,25 +50,25 @@ export enum LoadPixelMapCode {
*/
export enum LoadPhase {
// 图片加载阶段
PHASE_LOAD = "load",
PHASE_LOAD = 'load',
// 网络请求下载阶段
PHASE_NET = "net",
PHASE_NET = 'net',
//获取图片格式阶段
PHASE_GET_FORMAT = "parse_format",
PHASE_GET_FORMAT = 'parse_format',
//自定义下载阶段 customGetImage
PHASE_CUSTOM_LOAD = "customGetImage",
PHASE_CUSTOM_LOAD = 'customGetImage',
// createPixelMap 阶段
PHASE_CREATE_SOURCE = "createImageSource",
PHASE_CREATE_SOURCE = 'createImageSource',
//createPixelMap 阶段
PHASE_CREATE_PIXEL_MAP = "createPixelMap",
PHASE_CREATE_PIXEL_MAP = 'createPixelMap',
//请求队列排队阶段
PHASE_THREAD_QUEUE = "thread_queue",
PHASE_THREAD_QUEUE = 'thread_queue',
//图片解析阶段
PHASE_PARSE_IAMGE = "parseImage",
PHASE_PARSE_IAMGE = 'parseImage',
//加载解析datashare:// 或者file:// 阶段
PHASE_SHARE_FILE = "datashare_or_file",
PHASE_SHARE_FILE = 'datashare_or_file',
//加载解析本地文件阶段
PHASE_LOCAL_FILE = "load_local_file",
PHASE_LOCAL_FILE = 'load_local_file',
//图片加载解析完成,即将显示的阶段
PHASE_WILL_SHOW = "will_show",
PHASE_WILL_SHOW = 'will_show',
}

View File

@ -80,7 +80,7 @@ export class FileTypeUtil {
return false; // 文件长度不足,无法匹配魔数
}
for (let i = fileType == "heic" ? 4 : 0; i < signature.length; i++) {
for (let i = fileType == 'heic' ? 4 : 0; i < signature.length; i++) {
if (fileData[i] !== signature[i]) {
return false; // 魔数不匹配
}

View File

@ -47,7 +47,7 @@ export class FileUtils {
}
return true
} catch (err) {
LogUtil.error("FileUtils deleteFileSync failed: err msg=" + err.message + " err code=" + err.code);
LogUtil.error('FileUtils deleteFileSync failed: err msg=' + err.message + ' err code=' + err.code);
return false
}
}
@ -63,7 +63,7 @@ export class FileUtils {
try {
await fs.unlink(path)
} catch (err) {
LogUtil.error("FileUtils deleteFile failed: err msg=" + err.message + " err code=" + err.code);
LogUtil.error('FileUtils deleteFile failed: err msg=' + err.message + ' err code=' + err.code);
}
}
@ -82,7 +82,7 @@ export class FileUtils {
return true
}
catch (err) {
LogUtil.error("FileUtils writeDataSync failed: err msg=" + err.message + " err code=" + err.code);
LogUtil.error('FileUtils writeDataSync failed: err msg=' + err.message + ' err code=' + err.code);
return false
}
}
@ -102,7 +102,7 @@ export class FileUtils {
return true
}
catch (err) {
LogUtil.error("FileUtils writeData failed: err msg=" + err.message + " err code=" + err.code);
LogUtil.error('FileUtils writeData failed: err msg=' + err.message + ' err code=' + err.code);
return false
}
}
@ -122,7 +122,7 @@ export class FileUtils {
}
} catch (error) {
let err: BusinessError = error as BusinessError;
LogUtil.error("FileUtils exist failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils exist failed with error message: ' + err.message + ', error code: ' + err.code);
}
return false
}
@ -137,7 +137,7 @@ export class FileUtils {
let stat = fs.statSync(path)
return stat.size
} catch (e) {
LogUtil.error("FileUtils getFileSize e " + e)
LogUtil.error('FileUtils getFileSize e ' + e)
return -1
}
}
@ -159,7 +159,7 @@ export class FileUtils {
}
} catch (error) {
let err: BusinessError = error as BusinessError;
LogUtil.error("FileUtils readFileSync failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils readFileSync failed with error message: ' + err.message + ', error code: ' + err.code);
}
return undefined
}
@ -180,7 +180,7 @@ export class FileUtils {
return buf
} catch (error) {
let err: BusinessError = error as BusinessError;
LogUtil.error("FileUtils readFile failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils readFile failed with error message: ' + err.message + ', error code: ' + err.code);
}
return undefined
}
@ -211,7 +211,7 @@ export class FileUtils {
}
}
} catch (e) {
LogUtil.log("FileUtils createFolder err : " + e)
LogUtil.log('FileUtils createFolder err : ' + e)
}
}
@ -225,7 +225,7 @@ export class FileUtils {
return true
} catch (error) {
let err: BusinessError = error as BusinessError;
LogUtil.error("FileUtils createFolder failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils createFolder failed with error message: ' + err.message + ', error code: ' + err.code);
}
return false
}
@ -246,7 +246,7 @@ export class FileUtils {
}
catch (error) {
let err: BusinessError = error as BusinessError;
LogUtil.error("FileUtils existFolder failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils existFolder failed with error message: ' + err.message + ', error code: ' + err.code);
}
return false
}
@ -259,7 +259,7 @@ export class FileUtils {
fs.closeSync(fd)
return true
} catch (err) {
LogUtil.error("FileUtils writeFileSync failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils writeFileSync failed with error message: ' + err.message + ', error code: ' + err.code);
}
return false
}
@ -268,7 +268,7 @@ export class FileUtils {
try {
return fs.listFileSync(path)
} catch (err) {
LogUtil.error("FileUtils ListFileSync failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils ListFileSync failed with error message: ' + err.message + ', error code: ' + err.code);
}
return []
}
@ -277,7 +277,7 @@ export class FileUtils {
try {
return fs.listFile(path)
} catch (err) {
LogUtil.error("FileUtils ListFile failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils ListFile failed with error message: ' + err.message + ', error code: ' + err.code);
}
return []
}
@ -286,7 +286,7 @@ export class FileUtils {
try {
return fs.statSync(path)
} catch (err) {
LogUtil.error("FileUtils StatSync failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils StatSync failed with error message: ' + err.message + ', error code: ' + err.code);
}
return undefined
}
@ -295,7 +295,7 @@ export class FileUtils {
try {
return fs.stat(path)
} catch (err) {
LogUtil.error("FileUtils Stat failed with error message: " + err.message + ", error code: " + err.code);
LogUtil.error('FileUtils Stat failed with error message: ' + err.message + ', error code: ' + err.code);
}
return undefined
}

View File

@ -16,7 +16,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit';
export class LogUtil {
public static readonly DOMAIN: number = 0xD002220;
public static readonly TAG: string = "ImageKnife::";
public static readonly TAG: string = 'ImageKnife::';
public static debug(message: string, ...args: Object[]) {
hilog.debug(LogUtil.DOMAIN, LogUtil.TAG, message, args)