parent
3bbcca19cd
commit
0f16d4437a
|
@ -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'
|
||||
|
|
|
@ -237,4 +237,11 @@ struct IndexFunctionDemo {
|
|||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue