diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index 52767e4..5b60743 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -3,6 +3,8 @@ "buildOption": { "sourceOption": { "workers": [ + "./src/main/ets/pages/workers/worker1.js", + "./src/main/ets/pages/workers/gifParseWorker.ts", './src/main/ets/workers/GifLoadWorker.ts', './src/main/ets/workers/PngLoadWorker.ts', './src/main/ets/workers/MyWorker.ts' diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 748aa83..6812123 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -237,4 +237,11 @@ struct IndexFunctionDemo { .width('100%') .height('100%') } + + aboutToAppear() { + } + + onBackPress() { + + } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets index de47d3f..9a3b3f5 100644 --- a/entry/src/main/ets/pages/index.ets +++ b/entry/src/main/ets/pages/index.ets @@ -12,26 +12,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import router from '@ohos.router' -import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' -import worker from '@ohos.worker'; - +import router from '@system.router'; +import { + ImageKnifeComponent, + ImageKnifeOption, +} from '@ohos/imageknife' +import ArkWorker from '@ohos.worker' @Entry @Component struct IndexFunctionDemo { - private globalGifWorker: any = undefined - @State imageKnifeOption1: ImageKnifeOption = { - loadSrc: $r('app.media.icon'), + private globalGifWorker:any = undefined + @State imageKnifeOption1: ImageKnifeOption = + { + loadSrc: $r('app.media.icon'), - placeholderSrc: $r('app.media.icon_loading'), - errorholderSrc: $r('app.media.icon_failed') - }; - @State imageKnifeOption2: ImageKnifeOption = { - loadSrc: $r('app.media.icon'), + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed') + }; - placeholderSrc: $r('app.media.icon_loading'), - errorholderSrc: $r('app.media.icon_failed') - }; + @State imageKnifeOption2: ImageKnifeOption = + { + loadSrc: $r('app.media.icon'), + + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed') + }; build() { Scroll() { @@ -60,7 +65,7 @@ struct IndexFunctionDemo { placeholderSrc: $r('app.media.icon_loading'), errorholderSrc: $r('app.media.icon_failed'), - displayProgress: true, + displayProgress:true, } }).margin({ top: 5, left: 3 }) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300) @@ -80,16 +85,20 @@ struct IndexFunctionDemo { } aboutToAppear() { - //替代过时的ArkWorker.Worker - this.globalGifWorker = new worker.ThreadWorker('entry/ets/workers/GifLoadWorker.ts') + this.globalGifWorker = new ArkWorker.Worker('entry/ets/pages/workers/gifParseWorker.ts', { + type: 'classic', + name: 'ImageKnifeParseGIF' + }) // gif解析在子线程,请在页面构建后创建worker,注入imageknife globalThis.ImageKnife.setGifWorker(this.globalGifWorker) } - - aboutToDisappear() { - // 页面销毁 销毁worker - if (this.globalGifWorker) { + aboutToDisappear(){ + if(this.globalGifWorker){ this.globalGifWorker.terminate(); } } + + onBackPress() { + + } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/pngjTestCasePage.ets b/entry/src/main/ets/pages/pngjTestCasePage.ets index 55cea8f..7145b43 100644 --- a/entry/src/main/ets/pages/pngjTestCasePage.ets +++ b/entry/src/main/ets/pages/pngjTestCasePage.ets @@ -18,7 +18,6 @@ import resourceManager from '@ohos.resourceManager'; import { FileUtils } from '@ohos/imageknife' import featureability from '@ohos.ability.featureAbility' import ArkWorker from '@ohos.worker' -import worker from '@ohos.worker'; @Entry @Component @@ -110,8 +109,11 @@ struct PngjTestCasePage { if (!this.pngdecodeRun2) { this.pngdecodeRun2 = true; let pngj = new Pngj(); - let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') - pngj.readPngImageAsync(png_load_worker, this.pngSource1, (sender, value) => { + let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', { + type: 'classic', + name: 'readPngImageAsync' + }) + pngj.readPngImageAsync(worker, this.pngSource1, (sender, value) => { this.pngSource1 = sender this.hint2 = 'img with=' + value.width + ' img height=' + value.height + ' img depth=' + value.depth + ' img ctype=' + value.ctype @@ -152,8 +154,11 @@ struct PngjTestCasePage { if (!this.pngdecodeRun3) { this.pngdecodeRun3 = true; let pngj = new Pngj(); - let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') - pngj.writePngWithStringAsync(png_load_worker, 'hello world', this.pngSource3, (sender, value) => { + let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', { + type: 'classic', + name: 'writePngWithStringAsync' + }) + pngj.writePngWithStringAsync(worker, 'hello world', this.pngSource3, (sender, value) => { this.pngSource3 = sender FileUtils.getInstance().createFileProcess( this.rootFolder + '/pngj', @@ -199,8 +204,11 @@ struct PngjTestCasePage { if (!this.pngdecodeRun4) { this.pngdecodeRun4 = true; let pngj = new Pngj(); - let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') - pngj.writePngAsync(png_load_worker, this.pngSource4, (sender, value) => { + let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', { + type: 'classic', + name: 'writePngAsync' + }) + pngj.writePngAsync(worker, this.pngSource4, (sender, value) => { this.pngSource4 = sender FileUtils.getInstance().createFileProcess( this.rootFolder + '/pngj', diff --git a/entry/src/main/ets/pages/workers/gifParseWorker.ts b/entry/src/main/ets/pages/workers/gifParseWorker.ts new file mode 100644 index 0000000..427f5ab --- /dev/null +++ b/entry/src/main/ets/pages/workers/gifParseWorker.ts @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import arkWorker from '@ohos.worker'; +import { gifHandler } from '@ohos/imageknife/GifWorker' + +arkWorker.parentPort.onmessage = gifHandler; + + + + + + diff --git a/entry/src/main/ets/pages/workers/worker1.js b/entry/src/main/ets/pages/workers/worker1.js new file mode 100644 index 0000000..9aff18e --- /dev/null +++ b/entry/src/main/ets/pages/workers/worker1.js @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import arkWorker from '@ohos.worker'; + +import {handler} from '@ohos/imageknife/PngWork' + +arkWorker.parentPort.onmessage = handler + + + + + + + + +