From 89b4e7cd001d0f7e6fe00d9440573a73b445fa91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=B3=BD=E6=82=9F?= Date: Fri, 2 Dec 2022 03:10:56 +0000 Subject: [PATCH] update zh-cn/application-dev/reference/apis/js-apis-image.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 冯泽悟 --- .../reference/apis/js-apis-image.md | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-image.md b/zh-cn/application-dev/reference/apis/js-apis-image.md index ec69c7ebf6..c2da9e59ad 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-image.md +++ b/zh-cn/application-dev/reference/apis/js-apis-image.md @@ -2127,26 +2127,25 @@ queueImage(interface: Image, callback: AsyncCallback\): void **示例:** ```js -var creator = image.createImageCreator(WIDTH, HEIGHT, FORMAT, CAPACITY); -var img = await creator.dequeueImage(); -const JPEG = 4; -var component = await img.getComponent(JPEG); -//绘制图片 -var bufferArr = new Uint8Array(component.byteBuffer); -for (var i = 0; i < bufferArr.length; i += 4) { - bufferArr[i] = 0; //B - bufferArr[i + 1] = 0; //G - bufferArr[i + 2] = 255; //R - bufferArr[i + 3] = 255; //A -} -creator.queueImage(img, (err) => { - if (err) { - console.info('queueImage failed: ' + err); +creator.dequeueImage().then(img => { + const JPEG = 4; + var component = await img.getComponent(JPEG); + //绘制图片 + var bufferArr = new Uint8Array(component.byteBuffer); + for (var i = 0; i < bufferArr.length; i += 4) { + bufferArr[i] = 0; //B + bufferArr[i + 1] = 0; //G + bufferArr[i + 2] = 255; //R + bufferArr[i + 3] = 255; //A } - console.info('queueImage succeeded'); + creator.queueImage(img, (err) => { + if (err) { + console.info('queueImage failed: ' + err); + } + console.info('queueImage succeeded'); + }) }) - ``` ### queueImage9+ @@ -2172,22 +2171,22 @@ queueImage(interface: Image): Promise\ **示例:** ```js -var creator = image.createImageCreator(8192, 8, 4, 8); -var img = await creator.dequeueImage(); -const JPEG = 4; -var component = await img.getComponent(JPEG); -//绘制图片 -var bufferArr = new Uint8Array(component.byteBuffer); -for (var i = 0; i < bufferArr.length; i += 4) { - bufferArr[i] = 0; //B - bufferArr[i + 1] = 0; //G - bufferArr[i + 2] = 255; //R - bufferArr[i + 3] = 255; //A -} -creator.queueImage(img).then(() => { - console.info('queueImage succeeded.'); -}).catch(error => { - console.info('queueImage failed: ' + error); +creator.dequeueImage().then(img => { + const JPEG = 4; + var component = await img.getComponent(JPEG); + //绘制图片 + var bufferArr = new Uint8Array(component.byteBuffer); + for (var i = 0; i < bufferArr.length; i += 4) { + bufferArr[i] = 0; //B + bufferArr[i + 1] = 0; //G + bufferArr[i + 2] = 255; //R + bufferArr[i + 3] = 255; //A + } + creator.queueImage(img).then(() => { + console.info('queueImage succeeded.'); + }).catch(error => { + console.info('queueImage failed: ' + error); + }) }) ``` -- GitLab