回退非必要修改文件

Signed-off-by: 李艺为 <15897461476@139.com>
This commit is contained in:
李艺为 2023-08-22 17:14:39 +08:00
parent 3bbcca19cd
commit 0f16d4437a
6 changed files with 107 additions and 29 deletions

View File

@ -3,6 +3,8 @@
"buildOption": { "buildOption": {
"sourceOption": { "sourceOption": {
"workers": [ "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/GifLoadWorker.ts',
'./src/main/ets/workers/PngLoadWorker.ts', './src/main/ets/workers/PngLoadWorker.ts',
'./src/main/ets/workers/MyWorker.ts' './src/main/ets/workers/MyWorker.ts'

View File

@ -237,4 +237,11 @@ struct IndexFunctionDemo {
.width('100%') .width('100%')
.height('100%') .height('100%')
} }
aboutToAppear() {
}
onBackPress() {
}
} }

View File

@ -12,21 +12,26 @@
* 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 router from '@ohos.router' import router from '@system.router';
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' import {
import worker from '@ohos.worker'; ImageKnifeComponent,
ImageKnifeOption,
} from '@ohos/imageknife'
import ArkWorker from '@ohos.worker'
@Entry @Entry
@Component @Component
struct IndexFunctionDemo { struct IndexFunctionDemo {
private globalGifWorker:any = undefined private globalGifWorker:any = undefined
@State imageKnifeOption1: ImageKnifeOption = { @State imageKnifeOption1: ImageKnifeOption =
{
loadSrc: $r('app.media.icon'), loadSrc: $r('app.media.icon'),
placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed') errorholderSrc: $r('app.media.icon_failed')
}; };
@State imageKnifeOption2: ImageKnifeOption = {
@State imageKnifeOption2: ImageKnifeOption =
{
loadSrc: $r('app.media.icon'), loadSrc: $r('app.media.icon'),
placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
@ -80,16 +85,20 @@ struct IndexFunctionDemo {
} }
aboutToAppear() { aboutToAppear() {
//替代过时的ArkWorker.Worker this.globalGifWorker = new ArkWorker.Worker('entry/ets/pages/workers/gifParseWorker.ts', {
this.globalGifWorker = new worker.ThreadWorker('entry/ets/workers/GifLoadWorker.ts') type: 'classic',
name: 'ImageKnifeParseGIF'
})
// gif解析在子线程,请在页面构建后创建worker,注入imageknife // gif解析在子线程,请在页面构建后创建worker,注入imageknife
globalThis.ImageKnife.setGifWorker(this.globalGifWorker) globalThis.ImageKnife.setGifWorker(this.globalGifWorker)
} }
aboutToDisappear(){ aboutToDisappear(){
// 页面销毁 销毁worker
if(this.globalGifWorker){ if(this.globalGifWorker){
this.globalGifWorker.terminate(); this.globalGifWorker.terminate();
} }
} }
onBackPress() {
}
} }

View File

@ -18,7 +18,6 @@ import resourceManager from '@ohos.resourceManager';
import { FileUtils } from '@ohos/imageknife' import { FileUtils } 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';
@Entry @Entry
@Component @Component
@ -110,8 +109,11 @@ struct PngjTestCasePage {
if (!this.pngdecodeRun2) { if (!this.pngdecodeRun2) {
this.pngdecodeRun2 = true; this.pngdecodeRun2 = true;
let pngj = new Pngj(); let pngj = new Pngj();
let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
pngj.readPngImageAsync(png_load_worker, this.pngSource1, (sender, value) => { type: 'classic',
name: 'readPngImageAsync'
})
pngj.readPngImageAsync(worker, this.pngSource1, (sender, value) => {
this.pngSource1 = sender this.pngSource1 = sender
this.hint2 = 'img with=' + value.width + ' img height=' + value.height this.hint2 = 'img with=' + value.width + ' img height=' + value.height
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype + ' img depth=' + value.depth + ' img ctype=' + value.ctype
@ -152,8 +154,11 @@ struct PngjTestCasePage {
if (!this.pngdecodeRun3) { if (!this.pngdecodeRun3) {
this.pngdecodeRun3 = true; this.pngdecodeRun3 = true;
let pngj = new Pngj(); let pngj = new Pngj();
let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
pngj.writePngWithStringAsync(png_load_worker, 'hello world', this.pngSource3, (sender, value) => { type: 'classic',
name: 'writePngWithStringAsync'
})
pngj.writePngWithStringAsync(worker, 'hello world', this.pngSource3, (sender, value) => {
this.pngSource3 = sender this.pngSource3 = sender
FileUtils.getInstance().createFileProcess( FileUtils.getInstance().createFileProcess(
this.rootFolder + '/pngj', this.rootFolder + '/pngj',
@ -199,8 +204,11 @@ struct PngjTestCasePage {
if (!this.pngdecodeRun4) { if (!this.pngdecodeRun4) {
this.pngdecodeRun4 = true; this.pngdecodeRun4 = true;
let pngj = new Pngj(); let pngj = new Pngj();
let png_load_worker = new worker.ThreadWorker('entry/ets/workers/PngLoadWorker.ts') let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
pngj.writePngAsync(png_load_worker, this.pngSource4, (sender, value) => { type: 'classic',
name: 'writePngAsync'
})
pngj.writePngAsync(worker, this.pngSource4, (sender, value) => {
this.pngSource4 = sender this.pngSource4 = sender
FileUtils.getInstance().createFileProcess( FileUtils.getInstance().createFileProcess(
this.rootFolder + '/pngj', this.rootFolder + '/pngj',

View File

@ -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;

View File

@ -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