1.ArkTs整改3 新增ImageKnifeGlobal类型,替换GlobalThis,设计改动文件比较多。

Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
zhoulisheng1 2023-09-18 14:33:36 +08:00
parent 6717f0667c
commit 803f4934ae
42 changed files with 244 additions and 186 deletions

View File

@ -15,7 +15,7 @@
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import window from '@ohos.window'; import window from '@ohos.window';
import { ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife'
import { CustomEngineKeyImpl } from './CustomEngineKeyImpl' import { CustomEngineKeyImpl } from './CustomEngineKeyImpl'
import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl';
@ -44,12 +44,12 @@ export default class EntryAbility extends UIAbility {
} }
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
this.context.resourceManager
globalThis.ImageKnife = ImageKnife.with(this.context); ImageKnife.with(this.context);
// 全局配置网络加载进度条 // 全局配置网络加载进度条
globalThis.ImageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) ImageKnifeGlobal.getInstance().getImageKnife().setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
// 全局配置缓存key // 全局配置缓存key
globalThis.ImageKnife.setEngineKeyImpl(new CustomEngineKeyImpl()) ImageKnifeGlobal.getInstance().getImageKnife().setEngineKeyImpl(new CustomEngineKeyImpl())
//开启ImageKnife所有级别日志开关 //开启ImageKnife所有级别日志开关
LogUtil.mLogLevel = LogUtil.ALL LogUtil.mLogLevel = LogUtil.ALL
} }

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { FileUtils } from '@ohos/imageknife' import { FileUtils, ImageKnifeGlobal} from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
@Entry @Entry
@ -41,7 +41,7 @@ struct basicTestFileIOPage {
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
let data = globalThis.ImageKnife.getImageKnifeContext().filesDir; let data:string = (ImageKnifeGlobal.getInstance().getHapContext as Record<string,Object>).filesDir as string;
console.log('ImageKnife filesPath = ' + data) console.log('ImageKnife filesPath = ' + data)
this.filePath = data this.filePath = data
this.appFilePath = data; this.appFilePath = data;
@ -51,7 +51,7 @@ struct basicTestFileIOPage {
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
let data = globalThis.ImageKnife.getImageKnifeContext().cacheDir; let data:string = (ImageKnifeGlobal.getInstance().getHapContext as Record<string,Object>).cacheDir as string;
console.log('ImageKnife cachesPath = ' + data) console.log('ImageKnife cachesPath = ' + data)
this.filePath = data this.filePath = data
this.appFilePath = data; this.appFilePath = data;
@ -79,8 +79,8 @@ struct basicTestFileIOPage {
this.appFilePath = 'appFilePath未取到值,请按顺序从上往下,从左往右依次测试' this.appFilePath = 'appFilePath未取到值,请按顺序从上往下,从左往右依次测试'
return return
} }
globalThis.ImageKnife.getImageKnifeContext().resourceManager ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMedia($r('app.media.gifSample').id) .getMediaContent($r('app.media.gifSample').id)
.then(data => { .then(data => {
console.log('result.getMedia') console.log('result.getMedia')
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength)

View File

@ -18,6 +18,7 @@ import { FileTypeUtil } from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { Base64 } from '@ohos/imageknife' import { Base64 } from '@ohos/imageknife'
import { ParseImageUtil } from '@ohos/imageknife' import { ParseImageUtil } from '@ohos/imageknife'
import { ImageKnifeGlobal } from '@ohos/imageknife'
@Entry @Entry
@Component @Component
@ -30,7 +31,8 @@ struct BasicTestMediaImage {
Flex({ direction: FlexDirection.Row }) { Flex({ direction: FlexDirection.Row }) {
Button('本地资源jpg') Button('本地资源jpg')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.jpgSample').id)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil(); let parseImageUtil = new ParseImageUtil();
@ -45,7 +47,8 @@ struct BasicTestMediaImage {
}).margin({ left: 15 }).backgroundColor(Color.Blue) }).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源png') Button('本地资源png')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.pngSample').id)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil(); let parseImageUtil = new ParseImageUtil();
@ -60,7 +63,8 @@ struct BasicTestMediaImage {
}).margin({ left: 15 }).backgroundColor(Color.Blue) }).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源bmp') Button('本地资源bmp')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.bmpSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.bmpSample').id)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil(); let parseImageUtil = new ParseImageUtil();
@ -75,7 +79,8 @@ struct BasicTestMediaImage {
}).margin({ left: 15 }).backgroundColor(Color.Blue) }).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源webp') Button('本地资源webp')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.jpgSample').id)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil(); let parseImageUtil = new ParseImageUtil();
@ -90,7 +95,8 @@ struct BasicTestMediaImage {
}).margin({ left: 15 }).backgroundColor(Color.Blue) }).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源gif') Button('本地资源gif')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.gifSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.gifSample').id)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil(); let parseImageUtil = new ParseImageUtil();

View File

@ -17,6 +17,7 @@ import {FileUtils} from '@ohos/imageknife'
import {FileTypeUtil} from '@ohos/imageknife' import {FileTypeUtil} from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import {Base64} from '@ohos/imageknife' import {Base64} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
@Entry @Entry
@Component @Component
@ -31,8 +32,9 @@ struct BasicTestResourceManagerPage {
Button('getMedia解析一张jpg图片') Button('getMedia解析一张jpg图片')
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample') ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.id,) .getMediaContent($r('app.media.jpgSample')
.id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
@ -47,7 +49,8 @@ struct BasicTestResourceManagerPage {
Button('getMediaBase64解析一张png图片') Button('getMediaBase64解析一张png图片')
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMediaBase64($r('app.media.pngSample') ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContentBase64($r('app.media.pngSample')
.id) .id)
.then(data => { .then(data => {
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data') console.log('ParseResClientBase64 - 本地加载资源 解析后数据data')

View File

@ -15,6 +15,7 @@
import {ImageKnife} from '@ohos/imageknife' import {ImageKnife} from '@ohos/imageknife'
import {OnRenameListener} from '@ohos/imageknife' import {OnRenameListener} from '@ohos/imageknife'
import {OnCompressListener} from '@ohos/imageknife' import {OnCompressListener} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
@Entry @Entry
@Component @Component
@ -94,7 +95,7 @@ struct CompressPage {
data.push($r('app.media.jpgSample')) data.push($r('app.media.jpgSample'))
console.info("asasd start compress") console.info("asasd start compress")
globalThis.ImageKnife (ImageKnifeGlobal.getInstance().getImageKnife())
.compressBuilder() .compressBuilder()
.load(data) .load(data)
.ignoreBy(100) .ignoreBy(100)
@ -135,7 +136,7 @@ struct CompressPage {
} }
console.info("asasd start compress") console.info("asasd start compress")
globalThis.ImageKnife (ImageKnifeGlobal.getInstance().getImageKnife())
.compressBuilder() .compressBuilder()
.load(data) .load(data)
.ignoreBy(100) .ignoreBy(100)

View File

@ -20,6 +20,7 @@ import { RecourseProvider } from '@ohos/imageknife'
import { PixelMapCrop } from '@ohos/imageknife' import { PixelMapCrop } from '@ohos/imageknife'
import { CropCallback } from '@ohos/imageknife' import { CropCallback } from '@ohos/imageknife'
import { FileUtils } from '@ohos/imageknife' import { FileUtils } from '@ohos/imageknife'
import { ImageKnifeGlobal } from '@ohos/imageknife'
@ -41,7 +42,8 @@ export struct CropImagePage2 {
Column() { Column() {
Button('点击解析图片') Button('点击解析图片')
.onClick(() => { .onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.bmpSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.bmpSample').id)
.then(data => { .then(data => {
let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data); let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data);
let optionx = new PixelMapCrop.Options(); let optionx = new PixelMapCrop.Options();

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {GIFParseImpl} from '@ohos/imageknife' import {GIFParseImpl} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker'; import worker from '@ohos.worker';
@Entry @Entry
@ -28,7 +29,8 @@ struct gifTestCasePage {
Flex({direction:FlexDirection.Row}){ Flex({direction:FlexDirection.Row}){
Button("加载gif图片") Button("加载gif图片")
.onClick(()=>{ .onClick(()=>{
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.test').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.test').id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength)
let gifImpl = new GIFParseImpl(); let gifImpl = new GIFParseImpl();
@ -49,7 +51,8 @@ struct gifTestCasePage {
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
Button("加载gif图片自带worker") Button("加载gif图片自带worker")
.onClick(()=>{ .onClick(()=>{
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.gifSample_single_frame').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.gifSample_single_frame').id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length = ' + data.byteLength) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length = ' + data.byteLength)
let local_worker = new worker.ThreadWorker('entry/ets/workers/GifLoadWorker.ts', { let local_worker = new worker.ThreadWorker('entry/ets/workers/GifLoadWorker.ts', {
@ -74,7 +77,8 @@ struct gifTestCasePage {
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
Button("加载gif图片全局配置worker") Button("加载gif图片全局配置worker")
.onClick(()=>{ .onClick(()=>{
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.test').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.test').id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length = ' + data.byteLength) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length = ' + data.byteLength)
@ -116,7 +120,7 @@ struct gifTestCasePage {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -16,6 +16,7 @@ import router from '@system.router';
import { import {
ImageKnifeComponent, ImageKnifeComponent,
ImageKnifeOption, ImageKnifeOption,
ImageKnifeGlobal,
} from '@ohos/imageknife' } from '@ohos/imageknife'
import worker from '@ohos.worker'; import worker from '@ohos.worker';
@ -91,7 +92,7 @@ struct IndexFunctionDemo {
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
// gif解析在子线程,请在页面构建后创建worker,注入imageknife // gif解析在子线程,请在页面构建后创建worker,注入imageknife
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -14,6 +14,7 @@
*/ */
import {ImageKnifeComponent, ScaleType} from '@ohos/imageknife' import {ImageKnifeComponent, ScaleType} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife' import {RotateImageTransformation} from '@ohos/imageknife'
import {Material} from './model/Material' import {Material} from './model/Material'
import {TestDataSource} from './model/TestDataSource' import {TestDataSource} from './model/TestDataSource'
@ -32,7 +33,7 @@ struct ManyPhotoShowPage {
Button('设置磁盘存储为50M') Button('设置磁盘存储为50M')
.onClick(()=>{ .onClick(()=>{
let disk:DiskLruCache = globalThis.ImageKnife.getDiskMemoryCache(); let disk:DiskLruCache = (ImageKnifeGlobal.getInstance().getImageKnife()).getDiskMemoryCache();
disk.setMaxSize(50*1024*1024) disk.setMaxSize(50*1024*1024)
Prompt.showToast({message:"设置成功"}) Prompt.showToast({message:"设置成功"})

View File

@ -15,7 +15,7 @@
import router from '@system.router'; import router from '@system.router';
import { Pngj } from '@ohos/imageknife' import { Pngj } from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { FileUtils } from '@ohos/imageknife' import { FileUtils,ImageKnifeGlobal } from '@ohos/imageknife'
import featureability from '@ohos.ability.featureAbility' import featureability from '@ohos.ability.featureAbility'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker'; import worker from '@ohos.worker';
@ -52,10 +52,10 @@ struct PngjTestCasePage {
Button(this.hint7).fontSize(30) Button(this.hint7).fontSize(30)
.onClick(() => { .onClick(() => {
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir; this.rootFolder = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).filesDir as string;
globalThis.ImageKnife.getImageKnifeContext() ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
.resourceManager .resourceManager as resourceManager.ResourceManager)
.getMedia($r('app.media.pngSample').id) .getMediaContent($r('app.media.pngSample').id)
.then(data => { .then(data => {
this.pngSource1 = FileUtils.getInstance().uint8ArrayToBuffer(data); this.pngSource1 = FileUtils.getInstance().uint8ArrayToBuffer(data);
this.hint7 = '获取buffer成功可以测试' this.hint7 = '获取buffer成功可以测试'
@ -91,10 +91,14 @@ struct PngjTestCasePage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button(this.hint8).fontSize(30) Button(this.hint8).fontSize(30)
.onClick(() => { .onClick(() => {
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir;
globalThis.ImageKnife.getImageKnifeContext()
.resourceManager
.getMedia($r('app.media.pngSample').id) this.rootFolder = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).filesDir as string;
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
.resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.pngSample').id)
.then(data => { .then(data => {
this.pngSource2 = FileUtils.getInstance().uint8ArrayToBuffer(data); this.pngSource2 = FileUtils.getInstance().uint8ArrayToBuffer(data);
this.hint8 = '获取buffer成功可以测试' this.hint8 = '获取buffer成功可以测试'
@ -136,10 +140,10 @@ struct PngjTestCasePage {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button(this.hint9).fontSize(30) Button(this.hint9).fontSize(30)
.onClick(() => { .onClick(() => {
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir; this.rootFolder = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).filesDir as string;
globalThis.ImageKnife.getImageKnifeContext() ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
.resourceManager .resourceManager as resourceManager.ResourceManager)
.getMedia($r('app.media.pngSample').id) .getMediaContent($r('app.media.pngSample').id)
.then(data => { .then(data => {
this.pngSource3 = FileUtils.getInstance().uint8ArrayToBuffer(data); this.pngSource3 = FileUtils.getInstance().uint8ArrayToBuffer(data);
this.hint9 = '获取buffer成功可以测试' this.hint9 = '获取buffer成功可以测试'
@ -186,10 +190,10 @@ struct PngjTestCasePage {
Button(this.hint10).fontSize(30) Button(this.hint10).fontSize(30)
.onClick(() => { .onClick(() => {
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir; this.rootFolder = (ImageKnifeGlobal.getInstance().getHapContext as Record<string,Object>).filesDir as string;
globalThis.ImageKnife.getImageKnifeContext() ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
.resourceManager .resourceManager as resourceManager.ResourceManager)
.getMedia($r('app.media.pngSample').id) .getMediaContent($r('app.media.pngSample').id)
.then(data => { .then(data => {
this.pngSource4 = FileUtils.getInstance().uint8ArrayToBuffer(data); this.pngSource4 = FileUtils.getInstance().uint8ArrayToBuffer(data);
this.hint10 = '获取buffer成功可以测试' this.hint10 = '获取buffer成功可以测试'

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {SVGParseImpl} from '@ohos/imageknife' import {SVGParseImpl} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
@Entry @Entry
@Component @Component
@ -28,7 +29,8 @@ struct svgTestCasePage {
Button("加载SVG图片") Button("加载SVG图片")
.onClick(()=>{ .onClick(()=>{
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.svgSample').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.svgSample').id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let svgImpl = new SVGParseImpl(); let svgImpl = new SVGParseImpl();
@ -57,7 +59,8 @@ struct svgTestCasePage {
Button("加载SVG图片") Button("加载SVG图片")
.onClick(()=>{ .onClick(()=>{
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.iconsvg').id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContent($r('app.media.iconsvg').id)
.then(data => { .then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data) console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let svgImpl = new SVGParseImpl(); let svgImpl = new SVGParseImpl();

View File

@ -16,6 +16,7 @@ import router from '@system.router';
import { import {
ImageKnifeComponent, ImageKnifeComponent,
ImageKnifeOption, ImageKnifeOption,
ImageKnifeGlobal,
ImageKnifeDrawFactory, ImageKnifeDrawFactory,
ScaleType ScaleType
} from '@ohos/imageknife' } from '@ohos/imageknife'
@ -90,7 +91,7 @@ struct tempUrlTestPage {
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
// gif解析在子线程,请在页面构建后创建worker,注入imageknife // gif解析在子线程,请在页面构建后创建worker,注入imageknife
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -17,6 +17,7 @@ import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/imageknife'
import {ImageKnifeComponent} from '@ohos/imageknife' import {ImageKnifeComponent} from '@ohos/imageknife'
import {TransformType} from '@ohos/imageknife' import {TransformType} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife' import {RotateImageTransformation} from '@ohos/imageknife'
@Entry @Entry
@ -206,4 +207,4 @@ struct TestAllCacheInfoPage {
} }
var ImageKnife = globalThis.ImageKnife var ImageKnife = (ImageKnifeGlobal.getInstance().getImageKnife())

View File

@ -14,6 +14,7 @@
*/ */
import {ImageKnifeComponent} from '@ohos/imageknife' import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife' import {RotateImageTransformation} from '@ohos/imageknife'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker' import worker from '@ohos.worker'
@ -90,7 +91,7 @@ struct TestGifDontAnimatePage {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' import { ImageKnife,ImageKnifeGlobal,ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'
import worker, { MessageEvents } from '@ohos.worker' import worker, { MessageEvents } from '@ohos.worker'
import Prompt from '@system.prompt' import Prompt from '@system.prompt'
@ -86,7 +86,7 @@ struct TestGifLoadWithWorkerPage {
this.my_gif_worker.onmessage = (e: MessageEvents) => { this.my_gif_worker.onmessage = (e: MessageEvents) => {
console.log("my_gif_worker.onmessage: " + e.data) console.log("my_gif_worker.onmessage: " + e.data)
} }
globalThis.ImageKnife.setGifWorker(this.my_gif_worker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.my_gif_worker)
//子线程加载gif,不阻塞toast的消失 //子线程加载gif,不阻塞toast的消失
this.options = { this.options = {
@ -102,7 +102,7 @@ struct TestGifLoadWithWorkerPage {
.onClick(() => { .onClick(() => {
console.log("ImageKnifeComponent button 加载gif onClick()") console.log("ImageKnifeComponent button 加载gif onClick()")
globalThis.ImageKnife.setGifWorker(undefined) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(undefined)
//主线程加载gif,阻塞toast的消失 //主线程加载gif,阻塞toast的消失
this.options = { this.options = {

View File

@ -14,6 +14,7 @@
*/ */
import {ImageKnifeComponent} from '@ohos/imageknife' import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife' import {RotateImageTransformation} from '@ohos/imageknife'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker' import worker from '@ohos.worker'
@ -190,7 +191,7 @@ struct TestImageKnifeOptionChangedPage {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -14,6 +14,7 @@
*/ */
import {ImageKnifeComponent} from '@ohos/imageknife' import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {ScaleType} from '@ohos/imageknife' import {ScaleType} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife' import {RotateImageTransformation} from '@ohos/imageknife'
import {GrayscaleTransformation} from '@ohos/imageknife' import {GrayscaleTransformation} from '@ohos/imageknife'
@ -203,7 +204,7 @@ struct TestImageKnifeOptionChangedPage3 {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -21,7 +21,8 @@ import {
SketchFilterTransformation, SketchFilterTransformation,
ScaleTypeHelper, ScaleTypeHelper,
IDrawLifeCycle, IDrawLifeCycle,
ScaleType ScaleType,
ImageKnifeGlobal
} from '@ohos/imageknife' } from '@ohos/imageknife'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker'; import worker from '@ohos.worker';
@ -118,7 +119,7 @@ struct TestImageKnifeOptionChangedPage4 {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) ImageKnifeGlobal.getInstance().getImageKnife().setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -16,6 +16,7 @@ import {
GrayscaleTransformation, GrayscaleTransformation,
ImageKnifeComponent, ImageKnifeComponent,
ImageKnifeData, ImageKnifeData,
ImageKnifeGlobal,
ImageKnifeOption, ImageKnifeOption,
RotateImageTransformation, RotateImageTransformation,
SketchFilterTransformation, SketchFilterTransformation,
@ -100,7 +101,7 @@ struct TestImageKnifeOptionChangedPage5 {
type: 'classic', type: 'classic',
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -15,6 +15,7 @@
import {ImageKnifeComponent} from '@ohos/imageknife' import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife' import {ImageKnifeOption} from '@ohos/imageknife'
import {RequestOption} from '@ohos/imageknife' import {RequestOption} from '@ohos/imageknife'
import {ImageKnifeGlobal } from '@ohos/imageknife'
import ArkWorker from '@ohos.worker' import ArkWorker from '@ohos.worker'
import worker from '@ohos.worker' import worker from '@ohos.worker'
@ -90,7 +91,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -124,7 +125,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -159,7 +160,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -191,7 +192,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -230,7 +231,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -269,7 +270,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -310,7 +311,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -349,7 +350,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -388,7 +389,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -427,7 +428,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -466,7 +467,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -505,7 +506,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -544,7 +545,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -583,7 +584,7 @@ struct TestPreloadPage {
} }
return false; return false;
}) })
globalThis.ImageKnife.preload(request); ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
}) })
.margin({ left: 15 }) .margin({ left: 15 })
.backgroundColor(Color.Grey) .backgroundColor(Color.Grey)
@ -620,7 +621,7 @@ struct TestPreloadPage {
name: 'ImageKnifeParseGIF' name: 'ImageKnifeParseGIF'
}) })
// gif解析在子线程,请在页面构建后创建worker,注入imageknife // gif解析在子线程,请在页面构建后创建worker,注入imageknife
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) ImageKnifeGlobal.getInstance().getImageKnife().setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
if(this.globalGifWorker){ if(this.globalGifWorker){

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { RequestOption } from '@ohos/imageknife' import { RequestOption,ImageKnifeGlobal} from '@ohos/imageknife'
import { CropCircleTransformation } from '@ohos/imageknife' import { CropCircleTransformation } from '@ohos/imageknife'
import { RoundedCornersTransformation } from '@ohos/imageknife' import { RoundedCornersTransformation } from '@ohos/imageknife'
import { import {
@ -1015,4 +1015,4 @@ struct TransformPixelMapPage {
} }
} }
var ImageKnife = globalThis.ImageKnife var ImageKnife = ImageKnifeGlobal.getInstance().getImageKnife();

View File

@ -19,25 +19,25 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
export default function abilityTest() { export default function abilityTest() {
describe('ActsAbilityTest', function () { describe('ActsAbilityTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('assertContain',0, function () { it('assertContain',0, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
let a = 'abc' let a = 'abc'

View File

@ -14,41 +14,41 @@
*/ */
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import {ImageKnife,ImageKnifeDrawFactory} from '@ohos/imageknife' import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife'
export default function ImageKnifeTest() { export default function ImageKnifeTest() {
describe('ImageKnifeTest', function () { describe('ImageKnifeTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('TestGlobalImageKnife',0, function () { it('TestGlobalImageKnife',0, ()=> {
globalThis.ImageKnife = ImageKnife.with(globalThis.TestAbilityContext) let global:ImageKnifeGlobal = ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext())
expect(globalThis.ImageKnife).not().assertUndefined() expect(global.getImageKnife()).not().assertUndefined()
}) })
it('TestGlobalDefaultLifeCycle',1, function () { it('TestGlobalDefaultLifeCycle',1, ()=> {
globalThis.ImageKnife = ImageKnife.with(globalThis.TestAbilityContext) ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext())
globalThis.ImageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) (ImageKnifeGlobal.getInstance().getImageKnife()).setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
let globalLifeCycle = globalThis.ImageKnife.getDefaultLifeCycle(); let globalLifeCycle = (ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle();
expect(globalLifeCycle).not().assertUndefined() expect(globalLifeCycle).not().assertUndefined()
}) })

View File

@ -17,27 +17,27 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {LogUtil} from '@ohos/imageknife' import {LogUtil} from '@ohos/imageknife'
export default function LogUtilTest() { export default function LogUtilTest() {
describe('LogUtilTest', function () { describe('LogUtilTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('TestLogUtilLevel',0, function () { it('TestLogUtilLevel',0, ()=> {
console.log("tag:LogUtil LogUtil.mLogLevel="+LogUtil.mLogLevel); console.log("tag:LogUtil LogUtil.mLogLevel="+LogUtil.mLogLevel);
LogUtil.mLogLevel = LogUtil.OFF; LogUtil.mLogLevel = LogUtil.OFF;

View File

@ -17,33 +17,33 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {LruCache} from '@ohos/imageknife' // DiskLruCache用例由DiskLruCache三方库提供 import {LruCache} from '@ohos/imageknife' // DiskLruCache用例由DiskLruCache三方库提供
export default function lruCacheTest() { export default function lruCacheTest() {
describe('lruCacheTest', function () { describe('lruCacheTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('testLruCacheSize',0, function () { it('testLruCacheSize',0, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(100); let memoryCache = new LruCache<string, any>(100);
expect(memoryCache.size).assertEqual(0); expect(memoryCache.size).assertEqual(0);
expect(memoryCache.maxsize).assertEqual(100) expect(memoryCache.maxsize).assertEqual(100)
}) })
it('testLruCachePut',1, function () { it('testLruCachePut',1, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(5); let memoryCache = new LruCache<string, any>(5);
memoryCache.put("1","1"); memoryCache.put("1","1");
@ -57,7 +57,7 @@ export default function lruCacheTest() {
let result = memoryCache.get("1") let result = memoryCache.get("1")
expect(result).assertEqual(undefined) expect(result).assertEqual(undefined)
}) })
it('testLruCacheGet',2, function () { it('testLruCacheGet',2, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(5); let memoryCache = new LruCache<string, any>(5);
memoryCache.put("1","1"); memoryCache.put("1","1");
@ -71,7 +71,7 @@ export default function lruCacheTest() {
let result = memoryCache.get("2") let result = memoryCache.get("2")
expect(result).assertEqual("2") expect(result).assertEqual("2")
}) })
it('testLruCacheAlgorithm',3, function () { it('testLruCacheAlgorithm',3, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(5); let memoryCache = new LruCache<string, any>(5);
memoryCache.put("1","1"); memoryCache.put("1","1");
@ -83,14 +83,14 @@ export default function lruCacheTest() {
memoryCache.get("1"); memoryCache.get("1");
memoryCache.get("2"); memoryCache.get("2");
memoryCache.foreachLruCache(function (value, key, index) { memoryCache.foreachLruCache( (value, key, index)=> {
if(index == 0){ if(index == 0){
expect(key).assertEqual("2") expect(key).assertEqual("2")
expect(value).assertEqual("2") expect(value).assertEqual("2")
} }
}) })
}) })
it('testLruCacheRemove',4, function () { it('testLruCacheRemove',4, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(5); let memoryCache = new LruCache<string, any>(5);
memoryCache.put("1","1"); memoryCache.put("1","1");
@ -104,14 +104,14 @@ export default function lruCacheTest() {
memoryCache.remove("2"); memoryCache.remove("2");
memoryCache.foreachLruCache(function (value, key, index) { memoryCache.foreachLruCache( (value, key, index)=> {
if(index == 0){ if(index == 0){
expect(key).assertEqual("1") expect(key).assertEqual("1")
expect(value).assertEqual("1") expect(value).assertEqual("1")
} }
}) })
}) })
it('testLruCacheResize',5, function () { it('testLruCacheResize',5, ()=> {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let memoryCache = new LruCache<string, any>(5); let memoryCache = new LruCache<string, any>(5);
memoryCache.put("1","1"); memoryCache.put("1","1");

View File

@ -18,43 +18,43 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {RequestOption} from '@ohos/imageknife' import {RequestOption} from '@ohos/imageknife'
export default function RequestOptionTest() { export default function RequestOptionTest() {
describe('RequestOptionTest', function () { describe('RequestOptionTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach( ()=> {
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach( ()=> {
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll( ()=> {
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('TestRequestOption',0, function () { it('TestRequestOption',0, ()=> {
let option = new RequestOption(); let option = new RequestOption();
expect(option.requestListeners.length == 0).assertTrue() expect(option.requestListeners.length == 0).assertTrue()
}) })
it('TestConfigLoadSrc',1, function () { it('TestConfigLoadSrc',1, ()=> {
let option = new RequestOption(); let option = new RequestOption();
expect(option.loadSrc).assertEqual(undefined) expect(option.loadSrc).assertEqual(undefined)
option.loadSrc = $r('app.media.icon') option.loadSrc = $r('app.media.icon')
expect(JSON.stringify(option.loadSrc)).assertEqual(JSON.stringify($r('app.media.icon'))) expect(JSON.stringify(option.loadSrc)).assertEqual(JSON.stringify($r('app.media.icon')))
}) })
it('TestConfigViewSize',2, function () { it('TestConfigViewSize',2, ()=> {
let option = new RequestOption(); let option = new RequestOption();
option.loadSrc = $r('app.media.icon') option.loadSrc = $r('app.media.icon')
option.setImageViewSize({width:100,height:100}) option.setImageViewSize({width:100,height:100})
expect(JSON.stringify(option.size)).assertEqual(JSON.stringify({width:100,height:100})) expect(JSON.stringify(option.size)).assertEqual(JSON.stringify({width:100,height:100}))
}) })
it('TestNormalConfigInfo',3, function () { it('TestNormalConfigInfo',3, ()=>{
let option = new RequestOption(); let option = new RequestOption();
expect(option.strategy.getName()).assertEqual('AUTOMATIC') expect(option.strategy.getName()).assertEqual('AUTOMATIC')

View File

@ -39,46 +39,46 @@ import {
} from '@ohos/imageknife' } from '@ohos/imageknife'
export default function Transform() { export default function Transform() {
describe('Transform', function () { describe('Transform', ()=>{
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () { beforeAll(()=>{
// Presets an action, which is performed only once before all test cases of the test suite start. // 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. // This API supports only one parameter: preset action function.
}) })
beforeEach(function () { beforeEach(()=>{
// Presets an action, which is performed before each unit test case starts. // 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**. // 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. // This API supports only one parameter: preset action function.
}) })
afterEach(function () { afterEach(()=>{
// Presets a clear action, which is performed after each unit test case ends. // 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**. // 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. // This API supports only one parameter: clear action function.
}) })
afterAll(function () { afterAll(()=>{
// Presets a clear action, which is performed after all test cases of the test suite end. // 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. // This API supports only one parameter: clear action function.
}) })
it('TestBlurTransformation', 0, function () { it('TestBlurTransformation', 0, ()=>{
let blur = new BlurTransformation(15); let blur = new BlurTransformation(15);
expect(blur.getName()).assertEqual('BlurTransformation _mRadius:15') expect(blur.getName()).assertEqual('BlurTransformation _mRadius:15')
}) })
it('TestBrightnessFilterTransformation', 1, function () { it('TestBrightnessFilterTransformation', 1, ()=>{
let bright = new BrightnessFilterTransformation(20); let bright = new BrightnessFilterTransformation(20);
expect(bright.getName()).assertEqual("BrightnessFilterTransformation:20") expect(bright.getName()).assertEqual("BrightnessFilterTransformation:20")
}) })
it('TestContrastFilterTransformation', 2, function () { it('TestContrastFilterTransformation', 2, ()=>{
let constrast = new ContrastFilterTransformation(30); let constrast = new ContrastFilterTransformation(30);
expect(constrast.getName()).assertEqual("ContrastFilterTransformation:30") expect(constrast.getName()).assertEqual("ContrastFilterTransformation:30")
}) })
it('TestCropCircleTransformation', 3, function () { it('TestCropCircleTransformation', 3, ()=>{
let cropCircle = new CropCircleTransformation(); let cropCircle = new CropCircleTransformation();
expect(cropCircle.getName()).assertContain("CropCircleTransformation") expect(cropCircle.getName()).assertContain("CropCircleTransformation")
expect(cropCircle.getName()).assertContain(";mCenterX:") expect(cropCircle.getName()).assertContain(";mCenterX:")
expect(cropCircle.getName()).assertContain(";mCenterY:") expect(cropCircle.getName()).assertContain(";mCenterY:")
expect(cropCircle.getName()).assertContain(";mRadius:") expect(cropCircle.getName()).assertContain(";mRadius:")
}) })
it('TestCropCircleWithBorderTransformation', 4, function () { it('TestCropCircleWithBorderTransformation', 4, ()=>{
let CropCircleWithBorder = new CropCircleWithBorderTransformation(10,{r_color:100,g_color:100,b_color:100 }); let CropCircleWithBorder = new CropCircleWithBorderTransformation(10,{r_color:100,g_color:100,b_color:100 });
expect(CropCircleWithBorder.getName()).assertContain("CropCircleTransformation") expect(CropCircleWithBorder.getName()).assertContain("CropCircleTransformation")
expect(CropCircleWithBorder.getName()).assertContain(";mCenterX:") expect(CropCircleWithBorder.getName()).assertContain(";mCenterX:")
@ -89,63 +89,63 @@ export default function Transform() {
expect(CropCircleWithBorder.getName()).assertContain(";mGColor:") expect(CropCircleWithBorder.getName()).assertContain(";mGColor:")
expect(CropCircleWithBorder.getName()).assertContain(";mBColor:") expect(CropCircleWithBorder.getName()).assertContain(";mBColor:")
}) })
it('TestCropSquareTransformation', 5, function () { it('TestCropSquareTransformation', 5, ()=>{
let CropSquare = new CropSquareTransformation(); let CropSquare = new CropSquareTransformation();
expect(CropSquare.getName()).assertContain("CropSquareTransformation") expect(CropSquare.getName()).assertContain("CropSquareTransformation")
}) })
it('TestCropTransformation', 6, function () { it('TestCropTransformation', 6, ()=>{
let crop = new CropTransformation(10,10,CropType.CENTER); let crop = new CropTransformation(10,10,CropType.CENTER);
expect(crop.getName()).assertContain("CropCircleTransformation"+ ";mWidth:10" + ";mHeight:10" + ";mCropType:1" ) expect(crop.getName()).assertContain("CropCircleTransformation"+ ";mWidth:10" + ";mHeight:10" + ";mCropType:1" )
}) })
it('TestGrayscaleTransformation', 7, function () { it('TestGrayscaleTransformation', 7, ()=>{
let grayscale = new GrayscaleTransformation(); let grayscale = new GrayscaleTransformation();
expect(grayscale.getName()).assertContain("GrayscaleTransformation" ) expect(grayscale.getName()).assertContain("GrayscaleTransformation" )
}) })
it('TestInvertFilterTransformation', 8, function () { it('TestInvertFilterTransformation', 8, ()=>{
let invert = new InvertFilterTransformation(); let invert = new InvertFilterTransformation();
expect(invert.getName()).assertContain("InvertFilterTransformation" ) expect(invert.getName()).assertContain("InvertFilterTransformation" )
}) })
it('TestPixelationFilterTransformation', 9, function () { it('TestPixelationFilterTransformation', 9, ()=>{
let pixelation = new PixelationFilterTransformation(); let pixelation = new PixelationFilterTransformation();
expect(pixelation.getName()).assertContain("PixelationFilterTransformation" ) expect(pixelation.getName()).assertContain("PixelationFilterTransformation" )
}) })
it('TestRotateImageTransformation', 10, function () { it('TestRotateImageTransformation', 10, ()=>{
let rotateImage = new RotateImageTransformation(180); let rotateImage = new RotateImageTransformation(180);
expect(rotateImage.getName()).assertContain("RotateImageTransformation" + ";degreesToRotate:180") expect(rotateImage.getName()).assertContain("RotateImageTransformation" + ";degreesToRotate:180")
}) })
it('TestRoundedCornersTransformation', 11, function () { it('TestRoundedCornersTransformation', 11, ()=>{
let roundConer = new RoundedCornersTransformation({top_left:5,bottom_left:5,top_right:5,bottom_right:5}); let roundConer = new RoundedCornersTransformation({top_left:5,bottom_left:5,top_right:5,bottom_right:5});
expect(roundConer.getName()).assertContain("RoundedCornersTransformation" + ";mTop_left:" + 5 expect(roundConer.getName()).assertContain("RoundedCornersTransformation" + ";mTop_left:" + 5
+ ";mTop_right:" + 5 + ";mTop_right:" + 5
+ ";mBottom_left:" + 5 + ";mBottom_left:" + 5
+ ";mBottom_right:" + 5) + ";mBottom_right:" + 5)
}) })
it('TestSepiaFilterTransformation', 12, function () { it('TestSepiaFilterTransformation', 12, ()=>{
let speia = new SepiaFilterTransformation(); let speia = new SepiaFilterTransformation();
expect(speia.getName()).assertContain("SepiaFilterTransformation") expect(speia.getName()).assertContain("SepiaFilterTransformation")
}) })
it('TestSketchFilterTransformation', 13, function () { it('TestSketchFilterTransformation', 13, ()=>{
let Sketch = new SketchFilterTransformation(); let Sketch = new SketchFilterTransformation();
expect(Sketch.getName()).assertContain("SketchFilterTransformation") expect(Sketch.getName()).assertContain("SketchFilterTransformation")
}) })
it('TestMaskTransformation', 14, function () { it('TestMaskTransformation', 14, ()=>{
let mask = new MaskTransformation($r('app.media.icon')); let mask = new MaskTransformation($r('app.media.icon'));
expect(mask.getName()).assertContain("MaskTransformation") expect(mask.getName()).assertContain("MaskTransformation")
}) })
it('TestSwirlFilterTransformation', 15, function () { it('TestSwirlFilterTransformation', 15, ()=>{
let swirl = new SwirlFilterTransformation(10,180,[10,10]); let swirl = new SwirlFilterTransformation(10,180,[10,10]);
expect(swirl.getName()).assertContain("SwirlFilterTransformation") expect(swirl.getName()).assertContain("SwirlFilterTransformation")
}) })
it('TestKuwaharaFilterTransform', 16, function () { it('TestKuwaharaFilterTransform', 16, ()=>{
let kuwahara = new KuwaharaFilterTransform(10); let kuwahara = new KuwaharaFilterTransform(10);
expect(kuwahara.getName()).assertContain("KuwaharaFilterTransform _mRadius:10") expect(kuwahara.getName()).assertContain("KuwaharaFilterTransform _mRadius:10")
}) })
it('TestToonFilterTransform', 17, function () { it('TestToonFilterTransform', 17, ()=>{
let toon = new ToonFilterTransform(10); let toon = new ToonFilterTransform(10);
expect(toon.getName()).assertContain("ToonFilterTransform threshold:") expect(toon.getName()).assertContain("ToonFilterTransform threshold:")
expect(toon.getName()).assertContain(";quantizationLevels:") expect(toon.getName()).assertContain(";quantizationLevels:")
}) })
it('TestVignetteFilterTransform', 18, function () { it('TestVignetteFilterTransform', 18, ()=>{
let vignette = new VignetteFilterTransform([0.5, 0.5],[0.0, 0.0, 0.0],[0.3, 0.75]); let vignette = new VignetteFilterTransform([0.5, 0.5],[0.0, 0.0, 0.0],[0.3, 0.75]);
expect(vignette.getName()).assertContain("VignetteFilterTransform centerPoint:") expect(vignette.getName()).assertContain("VignetteFilterTransform centerPoint:")
expect(vignette.getName()).assertContain(";vignetteColor:") expect(vignette.getName()).assertContain(";vignetteColor:")

View File

@ -18,7 +18,7 @@ import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium'; import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test'; import testsuite from '../test/List.test';
import window from '@ohos.window'; import window from '@ohos.window';
import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife'
export default class TestAbility extends UIAbility { export default class TestAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
@ -30,7 +30,7 @@ export default class TestAbility extends UIAbility {
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
globalThis.TestAbilityContext = this.context.createModuleContext("entry_test") (ImageKnifeGlobal.getInstance().setHapContext(this.context.createModuleContext("entry_test")))
} }
onDestroy() { onDestroy() {

View File

@ -93,6 +93,7 @@ export * from './src/main/ets/components/3rd_party/upng/UPNG'
* ImageKnife * ImageKnife
*/ */
export * from './src/main/ets/components/imageknife/ImageKnife' export * from './src/main/ets/components/imageknife/ImageKnife'
export * from './src/main/ets/components/imageknife/ImageKnifeGlobal'
export * from './src/main/ets/components/imageknife/RequestOption' export * from './src/main/ets/components/imageknife/RequestOption'
export * from './src/main/ets/components/imageknife/ImageKnifeComponent' export * from './src/main/ets/components/imageknife/ImageKnifeComponent'
export * from './src/main/ets/components/imageknife/ImageKnifeDrawFactory' export * from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'

View File

@ -30,8 +30,7 @@ import type {IDataFetch} from '../imageknife/networkmanage/IDataFetch'
import {ParseResClient} from '../imageknife/resourcemanage/ParseResClient' import {ParseResClient} from '../imageknife/resourcemanage/ParseResClient'
import type {IResourceFetch} from '../imageknife/resourcemanage/IResourceFetch' import type {IResourceFetch} from '../imageknife/resourcemanage/IResourceFetch'
import {ImageKnifeData,ImageKnifeType} from '../imageknife/ImageKnifeData' import {ImageKnifeData,ImageKnifeType} from '../imageknife/ImageKnifeData'
import {FileUtils} from '../cache/FileUtils' import {ImageKnifeGlobal} from '../imageknife/ImageKnifeGlobal'
import {FileReader} from '../cache/FileReader'
import image from "@ohos.multimedia.image" import image from "@ohos.multimedia.image"
import {CompressBuilder} from "../imageknife/compress/CompressBuilder" import {CompressBuilder} from "../imageknife/compress/CompressBuilder"
import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle'
@ -39,7 +38,7 @@ import {LogUtil} from '../imageknife/utils/LogUtil'
export class ImageKnife { export class ImageKnife {
static readonly SEPARATOR: string = '/' static readonly SEPARATOR: string = '/'
private imageKnifeContext;
private memoryCache: LruCache<string, any>; private memoryCache: LruCache<string, any>;
private diskMemoryCache: DiskLruCache; private diskMemoryCache: DiskLruCache;
private dataFetch: IDataFetch; private dataFetch: IDataFetch;
@ -64,14 +63,13 @@ export class ImageKnife {
// 开发者可配置全局缓存 // 开发者可配置全局缓存
private engineKeyImpl: EngineKeyInterface; private engineKeyImpl: EngineKeyInterface;
private constructor(imgCtx) { private constructor() {
this.imageKnifeContext = imgCtx;
// 构造方法传入size 为保存文件个数 // 构造方法传入size 为保存文件个数
this.memoryCache = new LruCache<string, any>(100); this.memoryCache = new LruCache<string, any>(100);
// 创建disk缓存 传入的size 为多少比特 比如20KB 传入20*1024 // 创建disk缓存 传入的size 为多少比特 比如20KB 传入20*1024
this.diskMemoryCache = DiskLruCache.create(this.imageKnifeContext); this.diskMemoryCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext());
// 创建网络下载能力 // 创建网络下载能力
this.dataFetch = new DownloadClient(); this.dataFetch = new DownloadClient();
@ -80,7 +78,7 @@ export class ImageKnife {
this.resourceFetch = new ParseResClient(); this.resourceFetch = new ParseResClient();
// 初始化本地 文件保存 // 初始化本地 文件保存
this.filesPath = this.imageKnifeContext.filesDir; this.filesPath = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).filesDir as string;
this.runningRequest = new Array(); this.runningRequest = new Array();
this.pendingRequest = new Array(); this.pendingRequest = new Array();
@ -95,11 +93,20 @@ export class ImageKnife {
return this.memoryCache; return this.memoryCache;
} }
public static with(context): ImageKnife{ public static with(context:Record<string,Object>): ImageKnifeGlobal{
if (!this.sInstance) { // 存入hapContext;
this.sInstance = new ImageKnife(context); let global:ImageKnifeGlobal = ImageKnifeGlobal.getInstance();
global.setHapContext(context)
// 初始化ImageKnife
if (!ImageKnife.sInstance) {
ImageKnife.sInstance = new ImageKnife();
} }
return this.sInstance;
// 存入ImageKnife
global.setImageKnife(ImageKnife.sInstance)
return global;
} }
getDiskMemoryCache(): DiskLruCache{ getDiskMemoryCache(): DiskLruCache{
@ -115,7 +122,7 @@ export class ImageKnife {
} }
getImageKnifeContext() { getImageKnifeContext() {
return this.imageKnifeContext; return ImageKnifeGlobal.getInstance().getHapContext();
} }
setMemoryCache(lrucache: LruCache<string, any>) { setMemoryCache(lrucache: LruCache<string, any>) {
@ -175,9 +182,9 @@ export class ImageKnife {
// 替代原来的DiskLruCache // 替代原来的DiskLruCache
public replaceDiskLruCache(size:number) { public replaceDiskLruCache(size:number) {
if (this.diskMemoryCache.getCacheMap().size() <= 0) { if (this.diskMemoryCache.getCacheMap().size() <= 0) {
this.diskMemoryCache = DiskLruCache.create(this.imageKnifeContext, size); this.diskMemoryCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext(), size);
} else { } else {
let newDiskLruCache = DiskLruCache.create(this.imageKnifeContext, size); let newDiskLruCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext(), size);
this.diskMemoryCache.foreachDiskLruCache(function (value, key, map) { this.diskMemoryCache.foreachDiskLruCache(function (value, key, map) {
newDiskLruCache.set(key, value); newDiskLruCache.set(key, value);
}) })

View File

@ -14,6 +14,7 @@
*/ */
import { ImageKnifeOption } from '../imageknife/ImageKnifeOption' import { ImageKnifeOption } from '../imageknife/ImageKnifeOption'
import { ImageKnifeGlobal } from '../imageknife/ImageKnifeGlobal'
import { TransformType } from '../imageknife/transform/TransformType' import { TransformType } from '../imageknife/transform/TransformType'
import { RequestOption } from '../imageknife/RequestOption' import { RequestOption } from '../imageknife/RequestOption'
import { ImageKnifeData } from '../imageknife/ImageKnifeData' import { ImageKnifeData } from '../imageknife/ImageKnifeData'
@ -272,7 +273,7 @@ export struct ImageKnifeComponent {
this.configCacheStrategy(request); this.configCacheStrategy(request);
this.configDisplay(request); this.configDisplay(request);
this.configRenderGpu(request); this.configRenderGpu(request);
globalThis.ImageKnife.call(request); ImageKnifeGlobal.getInstance().getImageKnife().call(request);
} }
displayPlaceholder(data: ImageKnifeData) { displayPlaceholder(data: ImageKnifeData) {
@ -280,7 +281,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayPlaceholder', this.context, data, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayPlaceholder', this.context, data, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
@ -298,7 +299,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayProgress', this.context, percent, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayProgress', this.context, percent, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
@ -316,7 +317,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayThumbSizeMultiplier', this.context, data, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayThumbSizeMultiplier', this.context, data, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
@ -332,7 +333,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayMainSource', this.context, data, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayMainSource', this.context, data, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
@ -350,7 +351,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayRetryholder', this.context, data, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayRetryholder', this.context, data, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
@ -367,7 +368,7 @@ export struct ImageKnifeComponent {
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {
if (!this.drawLifeCycleHasConsumed(globalThis.ImageKnife.getDefaultLifeCycle(), 'displayErrorholder', this.context, data, this.imageKnifeOption, if (!this.drawLifeCycleHasConsumed((ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(), 'displayErrorholder', this.context, data, this.imageKnifeOption,
this.currentWidth, this.currentHeight, (gifTimeId) => { this.currentWidth, this.currentHeight, (gifTimeId) => {
this.setGifTimeId(gifTimeId) this.setGifTimeId(gifTimeId)
})) { })) {

View File

@ -28,7 +28,7 @@ export class ImageKnifeGlobal {
private _objects = new Map<string, Object>(); private _objects = new Map<string, Object>();
public static getContext(): ImageKnifeGlobal { public static getInstance(): ImageKnifeGlobal {
if (!ImageKnifeGlobal.instance) { if (!ImageKnifeGlobal.instance) {
ImageKnifeGlobal.instance = new ImageKnifeGlobal(); ImageKnifeGlobal.instance = new ImageKnifeGlobal();
} }

View File

@ -46,6 +46,7 @@ import { KuwaharaFilterTransform } from '../imageknife/transform/KuwaharaFilterT
import { ToonFilterTransform } from '../imageknife/transform/ToonFilterTransform' import { ToonFilterTransform } from '../imageknife/transform/ToonFilterTransform'
import { VignetteFilterTransform } from '../imageknife/transform/VignetteFilterTransform' import { VignetteFilterTransform } from '../imageknife/transform/VignetteFilterTransform'
import { LogUtil } from '../imageknife/utils/LogUtil' import { LogUtil } from '../imageknife/utils/LogUtil'
import { ImageKnifeGlobal } from './ImageKnifeGlobal'
export class RequestOption { export class RequestOption {
loadSrc: string | PixelMap | Resource; loadSrc: string | PixelMap | Resource;
@ -436,16 +437,16 @@ export class RequestOption {
// 等落盘结束后主动调用#removeCurrentAndSearchNext方法 // 等落盘结束后主动调用#removeCurrentAndSearchNext方法
}else{ }else{
// 非落盘情况,直接进行寻找下一个加载 // 非落盘情况,直接进行寻找下一个加载
globalThis.ImageKnife.removeRunning(this); (ImageKnifeGlobal.getInstance().getImageKnife()).removeRunning(this);
} }
// 加载成功之后 // 加载成功之后
globalThis.ImageKnife.removeRunning(this); (ImageKnifeGlobal.getInstance().getImageKnife()).removeRunning(this);
} }
// 图片文件落盘之后会自动去寻找下一个数据加载 // 图片文件落盘之后会自动去寻找下一个数据加载
removeCurrentAndSearchNext(){ removeCurrentAndSearchNext(){
globalThis.ImageKnife.removeRunning(this); (ImageKnifeGlobal.getInstance().getImageKnife()).removeRunning(this);
} }
loadError(err) { loadError(err) {
@ -465,7 +466,7 @@ export class RequestOption {
} }
} }
// 加载失败之后 // 加载失败之后
globalThis.ImageKnife.removeRunning(this); (ImageKnifeGlobal.getInstance().getImageKnife()).removeRunning(this);
} }
} }

View File

@ -22,6 +22,7 @@ import {DataStringPathProvider} from '../compress/provider/DataStringPathProvide
import {RecourseProvider} from '../compress/provider/RecourseProvider' import {RecourseProvider} from '../compress/provider/RecourseProvider'
import { Engine } from '../compress/Engine' import { Engine } from '../compress/Engine'
import { ImageKnife } from '../ImageKnife' import { ImageKnife } from '../ImageKnife'
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
export class CompressBuilder { export class CompressBuilder {
private _mTargetDir: string; private _mTargetDir: string;
@ -106,7 +107,7 @@ export class CompressBuilder {
public async get():Promise<string> { public async get():Promise<string> {
if (!this._mTargetDir) { if (!this._mTargetDir) {
let context = globalThis.ImageKnife.getImageKnifeContext(); let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>);
let path = context.filesDir; let path = context.filesDir;
var timestamp = (new Date()).valueOf(); var timestamp = (new Date()).valueOf();
this._outFilePath = path + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg"; this._outFilePath = path + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
@ -201,7 +202,7 @@ export class CompressBuilder {
} }
private getImageCacheFile() { private getImageCacheFile() {
let context = globalThis.ImageKnife.getImageKnifeContext(); let context:Record<string,Object> = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>)
var timestamp = (new Date()).valueOf(); var timestamp = (new Date()).valueOf();
this._outFilePath = context.filesDir + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg"; this._outFilePath = context.filesDir + "/compress/" + timestamp + (Math.random() * 100).toFixed(0) + ".jpg";
this.startCompress(); this.startCompress();

View File

@ -16,6 +16,8 @@
import {CompressAdapter, PixelMapFormat} from "../provider/CompressAdapter" import {CompressAdapter, PixelMapFormat} from "../provider/CompressAdapter"
import {CompressDataListener} from "../listener/CompressDataListener" import {CompressDataListener} from "../listener/CompressDataListener"
import {FileTypeUtil} from '../../../imageknife/utils/FileTypeUtil' import {FileTypeUtil} from '../../../imageknife/utils/FileTypeUtil'
import { ImageKnifeGlobal } from '../../ImageKnifeGlobal';
import resourceManager from '@ohos.resourceManager';
export class RecourseProvider extends CompressAdapter { export class RecourseProvider extends CompressAdapter {
private static CHARS: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; private static CHARS: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@ -42,8 +44,8 @@ export class RecourseProvider extends CompressAdapter {
if (!this._mResourceData) { if (!this._mResourceData) {
throw Error("compress resource is empty"); throw Error("compress resource is empty");
} }
globalThis.ImageKnife.getImageKnifeContext().resourceManager ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMedia(this._mResourceData.id) .getMediaContent(this._mResourceData.id)
.then(data => { .then(data => {
let buffer = this.uint8ArrayToBuffer(data); let buffer = this.uint8ArrayToBuffer(data);
let fileTypeUtil = new FileTypeUtil() let fileTypeUtil = new FileTypeUtil()

View File

@ -19,6 +19,7 @@ import { NetworkDownloadClient } from './NetworkDownloadClient'
import { LoadLocalFileClient } from './LoadLocalFileClient' import { LoadLocalFileClient } from './LoadLocalFileClient'
import { LoadDataShareFileClient } from './LoadDataShareFileClient' import { LoadDataShareFileClient } from './LoadDataShareFileClient'
import loadRequest from '@ohos.request'; import loadRequest from '@ohos.request';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'
// 数据加载器 // 数据加载器
export class DownloadClient implements IDataFetch { export class DownloadClient implements IDataFetch {
@ -28,8 +29,11 @@ export class DownloadClient implements IDataFetch {
loadData(request: RequestOption, onCompleteFunction, onErrorFunction) { loadData(request: RequestOption, onCompleteFunction, onErrorFunction) {
if (typeof request.loadSrc == 'string') { if (typeof request.loadSrc == 'string') {
if (request.loadSrc.startsWith(globalThis.ImageKnife.getImageKnifeContext() let fileDir:string = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).filesDir as string;
.filesDir) || request.loadSrc.startsWith(globalThis.ImageKnife.getImageKnifeContext().cacheDir)) { let cacheDir:string = (ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).cacheDir as string
if (request.loadSrc.startsWith(fileDir) ||
request.loadSrc.startsWith(cacheDir)) {
// 本地沙盒 // 本地沙盒
this.localFileClient.loadData(request, onCompleteFunction, onErrorFunction) this.localFileClient.loadData(request, onCompleteFunction, onErrorFunction)
} else if (request.loadSrc.startsWith('datashare://') || request.loadSrc.startsWith('file://')) { } else if (request.loadSrc.startsWith('datashare://') || request.loadSrc.startsWith('file://')) {

View File

@ -19,7 +19,8 @@ import { SparkMD5 } from '../../3rd_party/sparkmd5/spark-md5'
import { FileUtils } from '../../cache/FileUtils' import { FileUtils } from '../../cache/FileUtils'
import loadRequest from '@ohos.request'; import loadRequest from '@ohos.request';
import { LogUtil } from '../utils/LogUtil' import { LogUtil } from '../utils/LogUtil'
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'
import common from '@ohos.app.ability.common'
// 数据加载器 // 数据加载器
export class NetworkDownloadClient implements IDataFetch { export class NetworkDownloadClient implements IDataFetch {
loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) { loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) {
@ -41,7 +42,7 @@ export class NetworkDownloadClient implements IDataFetch {
enableMetered: true, enableMetered: true,
}; };
let loadTask = null; let loadTask = null;
loadRequest.downloadFile(globalThis.ImageKnife.getImageKnifeContext(), downloadConfig).then(downloadTask => { loadRequest.downloadFile( (ImageKnifeGlobal.getInstance().getHapContext() as common.BaseContext ), downloadConfig).then(downloadTask => {
if (downloadTask) { if (downloadTask) {
loadTask = downloadTask; loadTask = downloadTask;

View File

@ -17,14 +17,15 @@ import type {IResourceFetch} from '../resourcemanage/IResourceFetch'
import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts' import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
export class ParseResClient implements IResourceFetch { export class ParseResClient implements IResourceFetch {
loadResource(res: Resource, onCompleteFunction, onErrorFunction) { loadResource(res: Resource, onCompleteFunction, onErrorFunction) {
let resId = res.id; let resId = res.id;
let resType = res.type; let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) { if (resType == ResourceTypeEts.MEDIA) {
globalThis.ImageKnife.getImageKnifeContext().resourceManager ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMedia(resId) .getMediaContent(resId)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);
onCompleteFunction(arrayBuffer) onCompleteFunction(arrayBuffer)

View File

@ -18,14 +18,15 @@ import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts'
import {Base64} from '../../cache/Base64' import {Base64} from '../../cache/Base64'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
export class ParseResClientBase64 implements IResourceFetch { export class ParseResClientBase64 implements IResourceFetch {
loadResource(res: Resource, onCompleteFunction, onErrorFunction) { loadResource(res: Resource, onCompleteFunction, onErrorFunction) {
let resId = res.id; let resId = res.id;
let resType = res.type; let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) { if (resType == ResourceTypeEts.MEDIA) {
globalThis.ImageKnife.getImageKnifeContext().resourceManager ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
.getMediaBase64(resId) .getMediaContentBase64(resId)
.then(data => { .then(data => {
let matchReg = ';base64,'; let matchReg = ';base64,';
var firstIndex = data.indexOf(matchReg) var firstIndex = data.indexOf(matchReg)

View File

@ -21,6 +21,8 @@ import { MaskUtils } from "../utils/MaskUtils"
import {LogUtil} from '../../imageknife/utils/LogUtil' import {LogUtil} from '../../imageknife/utils/LogUtil'
import image from "@ohos.multimedia.image" import image from "@ohos.multimedia.image"
import resmgr from "@ohos.resourceManager" import resmgr from "@ohos.resourceManager"
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'
import resourceManager from '@ohos.resourceManager'
export class MaskTransformation implements BaseTransform<PixelMap> { export class MaskTransformation implements BaseTransform<PixelMap> {
private _mResourceData: Resource; private _mResourceData: Resource;
@ -84,7 +86,7 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
if (!this._mResourceData) { if (!this._mResourceData) {
throw new Error("MaskTransformation resource is empty"); throw new Error("MaskTransformation resource is empty");
} }
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia(this._mResourceData.id) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager).getMediaContent(this._mResourceData.id)
.then(array => { .then(array => {
let buffer = array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset); let buffer = array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
var imageSource = image.createImageSource(buffer as any); var imageSource = image.createImageSource(buffer as any);

View File

@ -12,6 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
import type {DataCallBack} from "../interface/DataCallBack" import type {DataCallBack} from "../interface/DataCallBack"
export namespace ColorUtils { export namespace ColorUtils {
@ -23,7 +25,7 @@ export namespace ColorUtils {
export function parseColor(c: string, callback: DataCallBack<string>) { export function parseColor(c: string, callback: DataCallBack<string>) {
var reColor = 'sys.color.' + c; var reColor = 'sys.color.' + c;
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getString($r(reColor) ((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager).getString($r(reColor)
.id, (err, color) => { .id, (err, color) => {
if (!err) { if (!err) {
var cos = JSON.stringify(color); var cos = JSON.stringify(color);

View File

@ -18,13 +18,14 @@ import { LoadType } from '../../../../../../../GifWorker'
import { parseBufferToFrame } from './parse/GIFParse' import { parseBufferToFrame } from './parse/GIFParse'
import { LogUtil } from '../../utils/LogUtil' import { LogUtil } from '../../utils/LogUtil'
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
import { ImageKnifeGlobal } from '../../ImageKnifeGlobal'
export class GIFParseImpl implements IParseGif { export class GIFParseImpl implements IParseGif {
parseGifs(imageinfo: ArrayBuffer, callback: (data?, err?) => void, worker?,runMainThread?:boolean) { parseGifs(imageinfo: ArrayBuffer, callback: (data?, err?) => void, worker?,runMainThread?:boolean) {
let resolveWorker = worker; let resolveWorker = worker;
LogUtil.log('parseGifs resolveWorker1 is null =' + (resolveWorker == null)) LogUtil.log('parseGifs resolveWorker1 is null =' + (resolveWorker == null))
if (!resolveWorker) { if (!resolveWorker) {
resolveWorker = globalThis.ImageKnife.getGifWorker(); resolveWorker = ImageKnifeGlobal.getInstance().getImageKnife().getGifWorker();
} }
LogUtil.log('parseGifs resolveWorker2 is null =' + (resolveWorker == null)) LogUtil.log('parseGifs resolveWorker2 is null =' + (resolveWorker == null))