forked from floraachy/ImageKnife
1.pngj操作放入子线程完成。
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
476c80dd78
commit
82ad36f241
|
@ -30,13 +30,14 @@ struct PngjTestCasePage {
|
||||||
@State hint4: string = 'writePngWithString内容展示'
|
@State hint4: string = 'writePngWithString内容展示'
|
||||||
@State hint5: string = '测试readMetadata'
|
@State hint5: string = '测试readMetadata'
|
||||||
@State hint6: string = '测试writeMetadata'
|
@State hint6: string = '测试writeMetadata'
|
||||||
|
@State hint7: string = '首先点击获取PNG图片buffer'
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Text('pngj接口测试列表').fontSize(20)
|
Text('pngj接口测试列表').fontSize(20)
|
||||||
|
|
||||||
Button('点击获取Png图片buffer').fontSize(20)
|
Button(this.hint7).fontSize(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
|
||||||
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir;
|
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir;
|
||||||
|
@ -45,6 +46,7 @@ struct PngjTestCasePage {
|
||||||
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id)
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||||
|
this.hint7 = '获取buffer成功,可以测试'
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log('点击获取Png图片buffer err=' + err)
|
console.log('点击获取Png图片buffer err=' + err)
|
||||||
|
@ -52,60 +54,59 @@ struct PngjTestCasePage {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
// Button('测试readPngImageInfo')
|
||||||
|
// .onClick(() => {
|
||||||
|
// let pngj = new Pngj();
|
||||||
|
// pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
||||||
|
// this.hint1 = JSON.stringify(value);
|
||||||
|
// })
|
||||||
|
// }).margin({ top: 5, left: 10 })
|
||||||
|
// Button('测试readPngImage')
|
||||||
|
// .onClick(() => {
|
||||||
|
// let pngj = new Pngj();
|
||||||
|
// pngj.readPngImage(this.pngSource, (sender, value) => {
|
||||||
|
// this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
||||||
|
// + ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
||||||
|
// console.log('png data =' + value.data);
|
||||||
|
// })
|
||||||
|
// }).margin({ top: 5, left: 10 })
|
||||||
|
// Button('测试writePngWithString')
|
||||||
|
// .onClick(() => {
|
||||||
|
// let pngj = new Pngj();
|
||||||
|
// pngj.writePngWithString('hello world', this.pngSource, (sender, value) => {
|
||||||
|
//
|
||||||
|
// FileUtils.getInstance().createFileProcess(
|
||||||
|
// this.rootFolder + '/pngj',
|
||||||
|
// this.rootFolder + '/pngj/newPng.png',
|
||||||
|
// value)
|
||||||
|
// let png1 = new Uint8Array(value)
|
||||||
|
// this.hint3 = 'png写入后长度' + png1.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng.png' + '保存后使用2进制查看数据是否新增'
|
||||||
|
// })
|
||||||
|
// }).margin({ top: 5, left: 10 })
|
||||||
|
// Button('测试writePng')
|
||||||
|
// .onClick(() => {
|
||||||
|
// let pngj = new Pngj();
|
||||||
|
// pngj.writePng(this.pngSource, (sender, value) => {
|
||||||
|
// FileUtils.getInstance().createFileProcess(
|
||||||
|
// this.rootFolder + '/pngj',
|
||||||
|
// this.rootFolder + '/pngj/newPng2.png',
|
||||||
|
// value)
|
||||||
|
// let png2 = new Uint8Array(value)
|
||||||
|
// this.hint4 = 'png2未写入长度' + png2.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng2.png' + '保存后使用2进制查看数据是否新增'
|
||||||
|
// })
|
||||||
|
// }).margin({ top: 5, left: 10 })
|
||||||
|
// }.width('100%')
|
||||||
|
// .height(60).backgroundColor(Color.Pink)
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Button('测试readPngImageInfo')
|
Button('测试readPng')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
let pngj = new Pngj();
|
||||||
pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
||||||
this.hint1 = JSON.stringify(value);
|
this.hint1 = JSON.stringify(value);
|
||||||
})
|
})
|
||||||
}).margin({ top: 5, left: 10 })
|
}).margin({ top: 5, left: 10 })
|
||||||
Button('测试readPngImage')
|
Button('readPngAsync')
|
||||||
.onClick(() => {
|
|
||||||
let pngj = new Pngj();
|
|
||||||
pngj.readPngImage(this.pngSource, (sender, value) => {
|
|
||||||
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
|
||||||
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
|
||||||
console.log('png data =' + value.data);
|
|
||||||
})
|
|
||||||
}).margin({ top: 5, left: 10 })
|
|
||||||
Button('测试writePngWithString')
|
|
||||||
.onClick(() => {
|
|
||||||
let pngj = new Pngj();
|
|
||||||
pngj.writePngWithString('hello world', this.pngSource, (sender, value) => {
|
|
||||||
|
|
||||||
FileUtils.getInstance().createFileProcess(
|
|
||||||
this.rootFolder + '/pngj',
|
|
||||||
this.rootFolder + '/pngj/newPng.png',
|
|
||||||
value)
|
|
||||||
let png1 = new Uint8Array(value)
|
|
||||||
this.hint3 = 'png写入后长度' + png1.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng.png' + '保存后使用2进制查看数据是否新增'
|
|
||||||
})
|
|
||||||
}).margin({ top: 5, left: 10 })
|
|
||||||
Button('测试writePng')
|
|
||||||
.onClick(() => {
|
|
||||||
let pngj = new Pngj();
|
|
||||||
pngj.writePng(this.pngSource, (sender, value) => {
|
|
||||||
FileUtils.getInstance().createFileProcess(
|
|
||||||
this.rootFolder + '/pngj',
|
|
||||||
this.rootFolder + '/pngj/newPng2.png',
|
|
||||||
value)
|
|
||||||
let png2 = new Uint8Array(value)
|
|
||||||
this.hint4 = 'png2未写入长度' + png2.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng2.png' + '保存后使用2进制查看数据是否新增'
|
|
||||||
})
|
|
||||||
}).margin({ top: 5, left: 10 })
|
|
||||||
}.width('100%')
|
|
||||||
.height(60).backgroundColor(Color.Pink)
|
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
|
||||||
Button('测试readPngImageInfo')
|
|
||||||
.onClick(() => {
|
|
||||||
let pngj = new Pngj();
|
|
||||||
pngj.readPngImageInfo(this.pngSource, (sender, value) => {
|
|
||||||
this.hint1 = JSON.stringify(value);
|
|
||||||
})
|
|
||||||
}).margin({ top: 5, left: 10 })
|
|
||||||
Button('测试readPngImageAsync')
|
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
let pngj = new Pngj();
|
||||||
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
||||||
|
@ -118,7 +119,12 @@ struct PngjTestCasePage {
|
||||||
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
||||||
})
|
})
|
||||||
}).margin({ top: 5, left: 10 })
|
}).margin({ top: 5, left: 10 })
|
||||||
Button('测试writePngWithStringAsync')
|
|
||||||
|
}.width('100%')
|
||||||
|
.height(60).backgroundColor(Color.Pink)
|
||||||
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
|
||||||
|
Button('测试writePngWithString')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
let pngj = new Pngj();
|
||||||
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
||||||
|
@ -135,7 +141,7 @@ struct PngjTestCasePage {
|
||||||
this.hint3 = 'png写入后长度' + png1.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng.png' + '保存后使用2进制查看数据是否新增'
|
this.hint3 = 'png写入后长度' + png1.byteLength + '目录文件:' + this.rootFolder + '/pngj/newPng.png' + '保存后使用2进制查看数据是否新增'
|
||||||
})
|
})
|
||||||
}).margin({ top: 5, left: 10 })
|
}).margin({ top: 5, left: 10 })
|
||||||
Button('测试writePngAsync')
|
Button('writePng')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
let pngj = new Pngj();
|
||||||
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
|
||||||
|
@ -155,6 +161,7 @@ struct PngjTestCasePage {
|
||||||
}.width('100%')
|
}.width('100%')
|
||||||
.height(60).backgroundColor(Color.Pink)
|
.height(60).backgroundColor(Color.Pink)
|
||||||
|
|
||||||
|
|
||||||
Text(this.hint1)
|
Text(this.hint1)
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height(120)
|
.height(120)
|
||||||
|
|
|
@ -38,20 +38,8 @@ export function handler (e) {
|
||||||
let newPng3 = UPNG.encode(UPNG.toRGBA8(pngDecode3), pngDecode3.width, pngDecode3.height, 0)
|
let newPng3 = UPNG.encode(UPNG.toRGBA8(pngDecode3), pngDecode3.width, pngDecode3.height, 0)
|
||||||
let dataObj3 = { type: 'writePngAsync', data: newPng3, receiver: data.data}
|
let dataObj3 = { type: 'writePngAsync', data: newPng3, receiver: data.data}
|
||||||
arkWorker.parentPort.postMessage(dataObj3, [newPng3, data.data]);
|
arkWorker.parentPort.postMessage(dataObj3, [newPng3, data.data]);
|
||||||
break;
|
|
||||||
case 'normal':
|
|
||||||
arkWorker.parentPort.postMessage(data);
|
|
||||||
break;
|
|
||||||
case 'error':
|
|
||||||
throw new Error('123');
|
|
||||||
break;
|
|
||||||
case 'buffer':
|
|
||||||
let uint8Array = new Uint8Array(data.data);
|
|
||||||
arkWorker.parentPort.postMessage(data, [data.data]);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue