未验证 提交 faabc220 编写于 作者: 刘关鹏 提交者: Gitee

update zh-cn/application-dev/reference/apis/js-apis-image.md.

Signed-off-by: N刘关鹏 <liuguanpeng1@huawei.com>
上级 6a58098e
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## 导入模块 ## 导入模块
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
...@@ -35,7 +35,7 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -35,7 +35,7 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
...@@ -65,11 +65,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As ...@@ -65,11 +65,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As
**示例:** **示例:**
```js ```ts
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (error, pixelmap : image.PixelMap) => { image.createPixelMap(color, opts, (error : BusinessError, pixelmap : image.PixelMap) => {
if(error) { if(error) {
console.log('Failed to create pixelmap.'); console.log('Failed to create pixelmap.');
} else { } else {
...@@ -112,7 +112,7 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> ...@@ -112,7 +112,7 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(readBuffer).then(() => {
...@@ -139,9 +139,10 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -139,9 +139,10 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const readBuffer : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => { pixelmap.readPixelsToBuffer(readBuffer, (err : BusinessError, res : Object) => {
if(err) { if(err) {
console.log('Failed to read image pixel data.'); //不符合条件则进入 console.log('Failed to read image pixel data.'); //不符合条件则进入
} else { } else {
...@@ -172,7 +173,7 @@ readPixels(area: PositionArea): Promise\<void> ...@@ -172,7 +173,7 @@ readPixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const area : image.PositionArea = { const area : image.PositionArea = {
pixels: new ArrayBuffer(8), pixels: new ArrayBuffer(8),
...@@ -204,11 +205,12 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -204,11 +205,12 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap : image.PixelMap) => { image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => {
if(pixelmap == undefined){ if(pixelmap == undefined){
console.info('createPixelMap failed.'); console.info('createPixelMap failed.');
} else { } else {
...@@ -245,7 +247,7 @@ writePixels(area: PositionArea): Promise\<void> ...@@ -245,7 +247,7 @@ writePixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
...@@ -261,7 +263,7 @@ image.createPixelMap(color, opts) ...@@ -261,7 +263,7 @@ image.createPixelMap(color, opts)
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
} }
let bufferArr : Uint8Array = new Uint8Array(area.pixels); let bufferArr : Uint8Array = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) { for (let i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
...@@ -290,17 +292,18 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -290,17 +292,18 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const area : image.PositionArea = { pixels: new ArrayBuffer(8), const area : image.PositionArea = { pixels: new ArrayBuffer(8),
offset: 0, offset: 0,
stride: 8, stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
} }
let bufferArr : Uint8Array = new Uint8Array(area.pixels); let bufferArr : Uint8Array = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) { for (let i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
pixelmap.writePixels(area, (error) => { pixelmap.writePixels(area, (error : BusinessError) => {
if (error != undefined) { if (error != undefined) {
console.info('Failed to write pixelmap into the specified area.'); console.info('Failed to write pixelmap into the specified area.');
} else { } else {
...@@ -331,11 +334,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void> ...@@ -331,11 +334,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
for (var i = 0; i < bufferArr.length; i++) { for (let i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
pixelmap.writeBufferToPixels(color).then(() => { pixelmap.writeBufferToPixels(color).then(() => {
...@@ -362,13 +365,14 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -362,13 +365,14 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
for (var i = 0; i < bufferArr.length; i++) { for (let i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
pixelmap.writeBufferToPixels(color, function(err) { pixelmap.writeBufferToPixels(color, (err : BusinessError) => {
if (err) { if (err) {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
return; return;
...@@ -394,7 +398,7 @@ getImageInfo(): Promise\<ImageInfo> ...@@ -394,7 +398,7 @@ getImageInfo(): Promise\<ImageInfo>
**示例:** **示例:**
```js ```ts
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let opts : image.InitializationOptions = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
...@@ -428,14 +432,15 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -428,14 +432,15 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap : image.PixelMap) => { image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => {
if (pixelmap == undefined) { if (pixelmap == undefined) {
console.error("Failed to obtain the image pixel map information."); console.error("Failed to obtain the image pixel map information.");
} }
pixelmap.getImageInfo((err, imageInfo : image.ImageInfo) => { pixelmap.getImageInfo((err : BusinessError, imageInfo : image.ImageInfo) => {
if (imageInfo == undefined) { if (imageInfo == undefined) {
console.error("Failed to obtain the image pixel map information."); console.error("Failed to obtain the image pixel map information.");
} }
...@@ -462,11 +467,12 @@ getBytesNumberPerRow(): number ...@@ -462,11 +467,12 @@ getBytesNumberPerRow(): number
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err,pixelmap : image.PixelMap) => { image.createPixelMap(color, opts, (err : BusinessError, pixelmap : image.PixelMap) => {
let rowCount : number = pixelmap.getBytesNumberPerRow(); let rowCount : number = pixelmap.getBytesNumberPerRow();
}) })
``` ```
...@@ -487,7 +493,7 @@ getPixelBytesNumber(): number ...@@ -487,7 +493,7 @@ getPixelBytesNumber(): number
**示例:** **示例:**
```js ```ts
let pixelBytesNumber : number = pixelmap.getPixelBytesNumber(); let pixelBytesNumber : number = pixelmap.getPixelBytesNumber();
``` ```
...@@ -507,7 +513,7 @@ getDensity():number ...@@ -507,7 +513,7 @@ getDensity():number
**示例:** **示例:**
```js ```ts
let getDensity : number = pixelmap.getDensity(); let getDensity : number = pixelmap.getDensity();
``` ```
...@@ -528,9 +534,10 @@ opacity(rate: number, callback: AsyncCallback\<void>): void ...@@ -528,9 +534,10 @@ opacity(rate: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
var rate = 0.5; import {BusinessError} from '@ohos.base'
pixelmap.opacity(rate, (err) => { let rate = 0.5;
pixelmap.opacity(rate, (err : BusinessError) => {
if (err) { if (err) {
console.error("Failed to set opacity."); console.error("Failed to set opacity.");
return; return;
...@@ -562,7 +569,7 @@ opacity(rate: number): Promise\<void> ...@@ -562,7 +569,7 @@ opacity(rate: number): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.opacity(0.5); await pixelmap.opacity(0.5);
} }
...@@ -584,7 +591,7 @@ createAlphaPixelmap(): Promise\<PixelMap> ...@@ -584,7 +591,7 @@ createAlphaPixelmap(): Promise\<PixelMap>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.createAlphaPixelmap(); await pixelmap.createAlphaPixelmap();
} }
...@@ -606,8 +613,9 @@ createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void ...@@ -606,8 +613,9 @@ createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
**示例:** **示例:**
```js ```ts
pixelmap.createAlphaPixelmap((err, alphaPixelMap : image.PixelMap) => { import {BusinessError} from '@ohos.base'
pixelmap.createAlphaPixelmap((err : BusinessError, alphaPixelMap : image.PixelMap) => {
if (alphaPixelMap == undefined) { if (alphaPixelMap == undefined) {
console.info('Failed to obtain new pixel map.'); console.info('Failed to obtain new pixel map.');
} else { } else {
...@@ -634,7 +642,7 @@ scale(x: number, y: number, callback: AsyncCallback\<void>): void ...@@ -634,7 +642,7 @@ scale(x: number, y: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.scale(2.0, 1.0); await pixelmap.scale(2.0, 1.0);
} }
...@@ -663,7 +671,7 @@ scale(x: number, y: number): Promise\<void> ...@@ -663,7 +671,7 @@ scale(x: number, y: number): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.scale(2.0, 1.0); await pixelmap.scale(2.0, 1.0);
} }
...@@ -687,7 +695,7 @@ translate(x: number, y: number, callback: AsyncCallback\<void>): void ...@@ -687,7 +695,7 @@ translate(x: number, y: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.translate(3.0, 1.0); await pixelmap.translate(3.0, 1.0);
} }
...@@ -716,7 +724,7 @@ translate(x: number, y: number): Promise\<void> ...@@ -716,7 +724,7 @@ translate(x: number, y: number): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.translate(3.0, 1.0); await pixelmap.translate(3.0, 1.0);
} }
...@@ -739,9 +747,10 @@ rotate(angle: number, callback: AsyncCallback\<void>): void ...@@ -739,9 +747,10 @@ rotate(angle: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
var angle = 90.0; import {BusinessError} from '@ohos.base'
pixelmap.rotate(angle, (err) => { let angle = 90.0;
pixelmap.rotate(angle, (err : BusinessError) => {
if (err) { if (err) {
console.error("Failed to set rotation."); console.error("Failed to set rotation.");
return; return;
...@@ -773,7 +782,7 @@ rotate(angle: number): Promise\<void> ...@@ -773,7 +782,7 @@ rotate(angle: number): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.rotate(90.0); await pixelmap.rotate(90.0);
} }
...@@ -797,7 +806,7 @@ flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): vo ...@@ -797,7 +806,7 @@ flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): vo
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.flip(false, true); await pixelmap.flip(false, true);
} }
...@@ -826,7 +835,7 @@ flip(horizontal: boolean, vertical: boolean): Promise\<void> ...@@ -826,7 +835,7 @@ flip(horizontal: boolean, vertical: boolean): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.flip(false, true); await pixelmap.flip(false, true);
} }
...@@ -849,7 +858,7 @@ crop(region: Region, callback: AsyncCallback\<void>): void ...@@ -849,7 +858,7 @@ crop(region: Region, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
} }
...@@ -877,7 +886,7 @@ crop(region: Region): Promise\<void> ...@@ -877,7 +886,7 @@ crop(region: Region): Promise\<void>
**示例:** **示例:**
```js ```ts
async function Demo() { async function Demo() {
await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
} }
...@@ -909,10 +918,10 @@ getColorSpace(): colorSpaceManager.ColorSpaceManager ...@@ -909,10 +918,10 @@ getColorSpace(): colorSpaceManager.ColorSpaceManager
**示例:** **示例:**
```js ```ts
import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
async function Demo() { async function Demo() {
let csm = pixelmap.getColorSpace(); let csm : Object = pixelmap.getColorSpace();
} }
``` ```
...@@ -941,11 +950,11 @@ setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void ...@@ -941,11 +950,11 @@ setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void
**示例:** **示例:**
```js ```ts
import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
async function Demo() { async function Demo() {
let colorSpaceName = colorSpaceManager.ColorSpace.SRGB; let colorSpaceName = colorSpaceManager.ColorSpace.SRGB;
var csm = colorSpaceManager.create(colorSpaceName); let csm : colorSpaceManager.ColorSpaceManager = colorSpaceManager.create(colorSpaceName);
pixelmap.setColorSpace(csm); pixelmap.setColorSpace(csm);
} }
``` ```
...@@ -975,19 +984,19 @@ marshalling(sequence: rpc.MessageSequence): void ...@@ -975,19 +984,19 @@ marshalling(sequence: rpc.MessageSequence): void
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
class MySequence { class MySequence {
pixel_map; pixel_map;
constructor(pixelmap) { constructor(pixelmap : image.PixelMap) {
this.pixel_map = pixelmap; this.pixel_map = pixelmap;
} }
marshalling(messageSequence) { marshalling(messageSequence : rpc.MessageSequence) {
this.pixel_map.marshalling(messageSequence); this.pixel_map.marshalling(messageSequence);
return true; return true;
} }
async unmarshalling(messageSequence) { async unmarshalling(messageSequence : rpc.MessageSequence) {
let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}); let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}});
await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
this.pixel_map = pixelMap; this.pixel_map = pixelMap;
...@@ -1030,23 +1039,23 @@ unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap> ...@@ -1030,23 +1039,23 @@ unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>
| ------- | --------------------------------------------| | ------- | --------------------------------------------|
| 62980115 | If the input parameter invalid | | 62980115 | If the input parameter invalid |
| 62980097 | If the ipc error | | 62980097 | If the ipc error |
| 62980096 | If the Operation failed | | 62980096 | If fail to create async work |
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
class MySequence { class MySequence {
pixel_map; pixel_map;
constructor(pixelmap) { constructor(pixelmap : image.PixelMap) {
this.pixel_map = pixelmap; this.pixel_map = pixelmap;
} }
marshalling(messageSequence) { marshalling(messageSequence : rpc.MessageSequence) {
this.pixel_map.marshalling(messageSequence); this.pixel_map.marshalling(messageSequence);
return true; return true;
} }
async unmarshalling(messageSequence) { async unmarshalling(messageSequence : rpc.MessageSequence) {
let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}}); let pixelParcel : image.PixelMap = await image.createPixelMap(new ArrayBuffer(96), {size: { height:4, width: 6}});
await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => { await pixelParcel.unmarshalling(messageSequence).then(async (pixelMap : image.PixelMap) => {
this.pixel_map = pixelMap; this.pixel_map = pixelMap;
...@@ -1078,7 +1087,7 @@ release():Promise\<void> ...@@ -1078,7 +1087,7 @@ release():Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
pixelmap.release().then(() => { pixelmap.release().then(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
...@@ -1103,7 +1112,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -1103,7 +1112,7 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
pixelmap.release(() => { pixelmap.release(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
}) })
...@@ -1131,19 +1140,19 @@ createImageSource(uri: string): ImageSource ...@@ -1131,19 +1140,19 @@ createImageSource(uri: string): ImageSource
**示例:** **示例:**
```js ```ts
//Stage模型 //Stage模型
const context : Context = getContext(this); const context : Context = getContext(this);
const path : string= context.cacheDir + "/test.jpg"; const path : string = context.cacheDir + "/test.jpg";
const imageSourceApi : image.ImageSource = image.createImageSource(path); const imageSourceApi : image.ImageSource = image.createImageSource(path);
``` ```
```js ```ts
//FA模型 //FA模型
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
const context : Context = featureAbility.getContext(); const context : Context = featureAbility.getContext();
const path : string= context.getCacheDir() + "/test.jpg"; const path : string = context.getCacheDir() + "/test.jpg";
const imageSourceApi : image.ImageSource = image.createImageSource(path); const imageSourceApi : image.ImageSource = image.createImageSource(path);
``` ```
...@@ -1170,8 +1179,8 @@ createImageSource(uri: string, options: SourceOptions): ImageSource ...@@ -1170,8 +1179,8 @@ createImageSource(uri: string, options: SourceOptions): ImageSource
**示例:** **示例:**
```js ```ts
var sourceOptions : image.SourceOptions = { sourceDensity: 120 }; let sourceOptions : image.SourceOptions = { sourceDensity: 120 };
let imageSource : image.ImageSource = image.createImageSource('test.png', sourceOptions); let imageSource : image.ImageSource = image.createImageSource('test.png', sourceOptions);
``` ```
...@@ -1197,7 +1206,7 @@ createImageSource(fd: number): ImageSource ...@@ -1197,7 +1206,7 @@ createImageSource(fd: number): ImageSource
**示例:** **示例:**
```js ```ts
const imageSourceApi : image.ImageSource = image.createImageSource(0); const imageSourceApi : image.ImageSource = image.createImageSource(0);
``` ```
...@@ -1224,8 +1233,8 @@ createImageSource(fd: number, options: SourceOptions): ImageSource ...@@ -1224,8 +1233,8 @@ createImageSource(fd: number, options: SourceOptions): ImageSource
**示例:** **示例:**
```js ```ts
var sourceOptions : image.SourceOptions = { sourceDensity: 120 }; let sourceOptions : image.SourceOptions = { sourceDensity: 120 };
const imageSourceApi : image.ImageSource = image.createImageSource(0, sourceOptions); const imageSourceApi : image.ImageSource = image.createImageSource(0, sourceOptions);
``` ```
...@@ -1245,7 +1254,7 @@ createImageSource(buf: ArrayBuffer): ImageSource ...@@ -1245,7 +1254,7 @@ createImageSource(buf: ArrayBuffer): ImageSource
**示例:** **示例:**
```js ```ts
const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
const imageSourceApi : image.ImageSource = image.createImageSource(buf); const imageSourceApi : image.ImageSource = image.createImageSource(buf);
``` ```
...@@ -1273,7 +1282,7 @@ createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource ...@@ -1273,7 +1282,7 @@ createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
**示例:** **示例:**
```js ```ts
const data : ArrayBuffer= new ArrayBuffer(112); const data : ArrayBuffer= new ArrayBuffer(112);
const imageSourceApi : image.ImageSource = image.createImageSource(data); const imageSourceApi : image.ImageSource = image.createImageSource(data);
``` ```
...@@ -1300,7 +1309,7 @@ CreateIncrementalSource(buf: ArrayBuffer): ImageSource ...@@ -1300,7 +1309,7 @@ CreateIncrementalSource(buf: ArrayBuffer): ImageSource
**示例:** **示例:**
```js ```ts
const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf);
``` ```
...@@ -1328,7 +1337,7 @@ CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource ...@@ -1328,7 +1337,7 @@ CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
**示例:** **示例:**
```js ```ts
const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const buf : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi : image.ImageSource = image.CreateIncrementalSource(buf);
``` ```
...@@ -1362,8 +1371,9 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void ...@@ -1362,8 +1371,9 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.getImageInfo(0,(error, imageInfo : image.ImageInfo) => { import {BusinessError} from '@ohos.base'
imageSourceApi.getImageInfo(0,(error : BusinessError, imageInfo : image.ImageInfo) => {
if(error) { if(error) {
console.log('getImageInfo failed.'); console.log('getImageInfo failed.');
} else { } else {
...@@ -1388,7 +1398,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -1388,7 +1398,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.getImageInfo((imageInfo : image.ImageInfo) => { imageSourceApi.getImageInfo((imageInfo : image.ImageInfo) => {
console.log('Succeeded in obtaining the image information.'); console.log('Succeeded in obtaining the image information.');
}) })
...@@ -1416,7 +1426,7 @@ getImageInfo(index?: number): Promise\<ImageInfo> ...@@ -1416,7 +1426,7 @@ getImageInfo(index?: number): Promise\<ImageInfo>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
imageSourceApi.getImageInfo(0) imageSourceApi.getImageInfo(0)
.then((imageInfo : image.ImageInfo) => { .then((imageInfo : image.ImageInfo) => {
...@@ -1449,7 +1459,7 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string ...@@ -1449,7 +1459,7 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string
**示例:** **示例:**
```js ```ts
imageSourceApi.getImageProperty("BitsPerSample") imageSourceApi.getImageProperty("BitsPerSample")
.then((data : string) => { .then((data : string) => {
console.log('Succeeded in getting the value of the specified attribute key of the image.'); console.log('Succeeded in getting the value of the specified attribute key of the image.');
...@@ -1473,8 +1483,9 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void ...@@ -1473,8 +1483,9 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.getImageProperty("BitsPerSample",(error, data : string) => { import {BusinessError} from '@ohos.base'
imageSourceApi.getImageProperty("BitsPerSample",(error : BusinessError, data : string) => {
if(error) { if(error) {
console.log('Failed to get the value of the specified attribute key of the image.'); console.log('Failed to get the value of the specified attribute key of the image.');
} else { } else {
...@@ -1501,9 +1512,10 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa ...@@ -1501,9 +1512,10 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
let property : image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } let property : image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' }
imageSourceApi.getImageProperty("BitsPerSample",property,(error, data : string) => { imageSourceApi.getImageProperty("BitsPerSample",property,(error : BusinessError, data : string) => {
if(error) { if(error) {
console.log('Failed to get the value of the specified attribute key of the image.'); console.log('Failed to get the value of the specified attribute key of the image.');
} else { } else {
...@@ -1535,7 +1547,7 @@ modifyImageProperty(key: string, value: string): Promise\<void> ...@@ -1535,7 +1547,7 @@ modifyImageProperty(key: string, value: string): Promise\<void>
**示例:** **示例:**
```js ```ts
imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
const w : string = imageSourceApi.getImageProperty("ImageWidth"); const w : string = imageSourceApi.getImageProperty("ImageWidth");
console.info('w', w); console.info('w', w);
...@@ -1560,7 +1572,7 @@ modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): ...@@ -1560,7 +1572,7 @@ modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>):
**示例:** **示例:**
```js ```ts
imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {}) imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
``` ```
...@@ -1589,7 +1601,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number) ...@@ -1589,7 +1601,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number)
**示例:** **示例:**
```js ```ts
const array : ArrayBuffer = new ArrayBuffer(100); const array : ArrayBuffer = new ArrayBuffer(100);
imageSourceApi.updateData(array, false, 0, 10).then(data => { imageSourceApi.updateData(array, false, 0, 10).then(data => {
console.info('Succeeded in updating data.'); console.info('Succeeded in updating data.');
...@@ -1617,7 +1629,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, ...@@ -1617,7 +1629,7 @@ updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number,
**示例:** **示例:**
```js ```ts
const array : ArrayBuffer = new ArrayBuffer(100); const array : ArrayBuffer = new ArrayBuffer(100);
imageSourceApi.updateData(array, false, 0, 10,(error,data )=> { imageSourceApi.updateData(array, false, 0, 10,(error,data )=> {
if(data !== undefined){ if(data !== undefined){
...@@ -1648,7 +1660,7 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap> ...@@ -1648,7 +1660,7 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
imageSourceApi.createPixelMap().then((pixelmap : image.PixelMap) => { imageSourceApi.createPixelMap().then((pixelmap : image.PixelMap) => {
console.log('Succeeded in creating pixelmap object through image decoding parameters.'); console.log('Succeeded in creating pixelmap object through image decoding parameters.');
...@@ -1673,8 +1685,9 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void ...@@ -1673,8 +1685,9 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.createPixelMap((err, pixelmap : image.PixelMap) => { import {BusinessError} from '@ohos.base'
imageSourceApi.createPixelMap((err : BusinessError, pixelmap : image.PixelMap) => {
console.info('Succeeded in creating pixelmap object.'); console.info('Succeeded in creating pixelmap object.');
}) })
``` ```
...@@ -1696,7 +1709,7 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo ...@@ -1696,7 +1709,7 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
**示例:** **示例:**
```js ```ts
let decodingOptions : image.DecodingOptions = { let decodingOptions : image.DecodingOptions = {
sampleSize: 1, sampleSize: 1,
editable: true, editable: true,
...@@ -1706,7 +1719,7 @@ let decodingOptions : image.DecodingOptions = { ...@@ -1706,7 +1719,7 @@ let decodingOptions : image.DecodingOptions = {
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
index: 0 index: 0
}; };
imageSourceApi.createPixelMap(decodingOptions, pixelmap : image.PixelMap => { imageSourceApi.createPixelMap(decodingOptions, (pixelmap : image.PixelMap) => {
console.log('Succeeded in creating pixelmap object.'); console.log('Succeeded in creating pixelmap object.');
}) })
``` ```
...@@ -1745,7 +1758,7 @@ createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>; ...@@ -1745,7 +1758,7 @@ createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>;
**示例:** **示例:**
```js ```ts
let decodeOpts : image.DecodingOptions = { let decodeOpts : image.DecodingOptions = {
sampleSize: 1, sampleSize: 1,
editable: true, editable: true,
...@@ -1785,7 +1798,7 @@ createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void ...@@ -1785,7 +1798,7 @@ createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.createPixelMapList( (pixelmaplist : Array<image.PixelMap>) => { imageSourceApi.createPixelMapList( (pixelmaplist : Array<image.PixelMap>) => {
console.info('Succeeded in creating pixelmaplist object.'); console.info('Succeeded in creating pixelmaplist object.');
}) })
...@@ -1820,7 +1833,7 @@ createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<Pixe ...@@ -1820,7 +1833,7 @@ createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<Pixe
**示例:** **示例:**
```js ```ts
let decodeOpts : image.DecodingOptions = { let decodeOpts : image.DecodingOptions = {
sampleSize: 1, sampleSize: 1,
editable: true, editable: true,
...@@ -1864,7 +1877,7 @@ getDelayTimeList(callback: AsyncCallback<Array\<number>>): void; ...@@ -1864,7 +1877,7 @@ getDelayTimeList(callback: AsyncCallback<Array\<number>>): void;
**示例:** **示例:**
```js ```ts
imageSourceApi.getDelayTimeList( (delayTimes : Array<number>) => { imageSourceApi.getDelayTimeList( (delayTimes : Array<number>) => {
console.log('Succeeded in getting delay time.'); console.log('Succeeded in getting delay time.');
}); });
...@@ -1900,7 +1913,7 @@ getDelayTimeList(): Promise<Array\<number>>; ...@@ -1900,7 +1913,7 @@ getDelayTimeList(): Promise<Array\<number>>;
**示例:** **示例:**
```js ```ts
let delayTimes : Array<number> = imageSourceApi.getDelayTimeList(); let delayTimes : Array<number> = imageSourceApi.getDelayTimeList();
``` ```
...@@ -1934,7 +1947,7 @@ getFrameCount(callback: AsyncCallback\<number>): void; ...@@ -1934,7 +1947,7 @@ getFrameCount(callback: AsyncCallback\<number>): void;
**示例:** **示例:**
```js ```ts
imageSourceApi.getFrameCount( (frameCount : number) => { imageSourceApi.getFrameCount( (frameCount : number) => {
console.log('Succeeded in getting frame count.'); console.log('Succeeded in getting frame count.');
}); });
...@@ -1970,7 +1983,7 @@ getFrameCount(): Promise\<number>; ...@@ -1970,7 +1983,7 @@ getFrameCount(): Promise\<number>;
**示例:** **示例:**
```js ```ts
let frameCount : number = imageSourceApi.getFrameCount(); let frameCount : number = imageSourceApi.getFrameCount();
``` ```
...@@ -1990,7 +2003,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -1990,7 +2003,7 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
imageSourceApi.release(() => { imageSourceApi.release(() => {
console.log('release succeeded.'); console.log('release succeeded.');
}) })
...@@ -2012,7 +2025,7 @@ release(): Promise\<void> ...@@ -2012,7 +2025,7 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
imageSourceApi.release().then(()=>{ imageSourceApi.release().then(()=>{
console.log('Succeeded in releasing the image source instance.'); console.log('Succeeded in releasing the image source instance.');
...@@ -2037,7 +2050,7 @@ createImagePacker(): ImagePacker ...@@ -2037,7 +2050,7 @@ createImagePacker(): ImagePacker
**示例:** **示例:**
```js ```ts
const imagePackerApi : image.ImagePacker = image.createImagePacker(); const imagePackerApi : image.ImagePacker = image.createImagePacker();
``` ```
...@@ -2071,7 +2084,7 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr ...@@ -2071,7 +2084,7 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
**示例:** **示例:**
```js ```ts
const imageSourceApi : image.ImageSource = image.createImageSource(0); const imageSourceApi : image.ImageSource = image.createImageSource(0);
let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }; let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 };
imagePackerApi.packing(imageSourceApi, packOpts, data : ArrayBuffer => {}) imagePackerApi.packing(imageSourceApi, packOpts, data : ArrayBuffer => {})
...@@ -2100,12 +2113,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> ...@@ -2100,12 +2113,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const imageSourceApi : image.ImageSource = image.createImageSource(0); const imageSourceApi : image.ImageSource = image.createImageSource(0);
let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data : ArrayBuffer => { .then( (data : ArrayBuffer) => {
console.log('packing succeeded.'); console.log('packing succeeded.');
}).catch((error : BusinessError) => { }).catch((error : BusinessError) => {
console.log('packing failed.'); console.log('packing failed.');
...@@ -2130,13 +2143,13 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB ...@@ -2130,13 +2143,13 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB
**示例:** **示例:**
```js ```ts
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap : image.image.PixelMap) => { image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(pixelmap, packOpts, data : ArrayBuffer => { imagePackerApi.packing(pixelmap, packOpts, (data : ArrayBuffer) => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
}) })
}) })
...@@ -2165,7 +2178,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -2165,7 +2178,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4 const color : ArrayBuffer = new ArrayBuffer(96); //96为需要创建的像素buffer大小,取值为:height * width *4
let bufferArr : Uint8Array = new Uint8Array(color); let bufferArr : Uint8Array = new Uint8Array(color);
...@@ -2173,7 +2186,7 @@ let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size: ...@@ -2173,7 +2186,7 @@ let opts : image.InitializationOptions = { editable: true, pixelFormat: 3, size:
image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => { image.createPixelMap(color, opts).then((pixelmap : image.PixelMap) => {
let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 } let packOpts : image.PackingOption = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(pixelmap, packOpts) imagePackerApi.packing(pixelmap, packOpts)
.then( data : ArrayBuffer => { .then( (data : ArrayBuffer) => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
}).catch((error : BusinessError) => { }).catch((error : BusinessError) => {
console.log('Failed to pack the image..'); console.log('Failed to pack the image..');
...@@ -2197,7 +2210,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -2197,7 +2210,7 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
imagePackerApi.release(()=>{ imagePackerApi.release(()=>{
console.log('Succeeded in releasing image packaging.'); console.log('Succeeded in releasing image packaging.');
}) })
...@@ -2219,7 +2232,7 @@ release(): Promise\<void> ...@@ -2219,7 +2232,7 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
imagePackerApi.release().then(()=>{ imagePackerApi.release().then(()=>{
console.log('Succeeded in releasing image packaging.'); console.log('Succeeded in releasing image packaging.');
...@@ -2253,8 +2266,8 @@ createImageReceiver(width: number, height: number, format: number, capacity: num ...@@ -2253,8 +2266,8 @@ createImageReceiver(width: number, height: number, format: number, capacity: num
**示例:** **示例:**
```js ```ts
var receiver image.ImageReceiver = image.createImageReceiver(8192, 8, 2000, 8); let receiver : image.ImageReceiver = image.createImageReceiver(8192, 8, 2000, 8);
``` ```
## ImageReceiver<sup>9+</sup> ## ImageReceiver<sup>9+</sup>
...@@ -2289,8 +2302,9 @@ getReceivingSurfaceId(callback: AsyncCallback\<string>): void ...@@ -2289,8 +2302,9 @@ getReceivingSurfaceId(callback: AsyncCallback\<string>): void
**示例:** **示例:**
```js ```ts
receiver.getReceivingSurfaceId((err, id : string) => { import {BusinessError} from '@ohos.base'
receiver.getReceivingSurfaceId((err : BusinessError, id : string) => {
if(err) { if(err) {
console.log('getReceivingSurfaceId failed.'); console.log('getReceivingSurfaceId failed.');
} else { } else {
...@@ -2315,7 +2329,7 @@ getReceivingSurfaceId(): Promise\<string> ...@@ -2315,7 +2329,7 @@ getReceivingSurfaceId(): Promise\<string>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
receiver.getReceivingSurfaceId().then( (id : string) => { receiver.getReceivingSurfaceId().then( (id : string) => {
console.log('getReceivingSurfaceId succeeded.'); console.log('getReceivingSurfaceId succeeded.');
...@@ -2340,8 +2354,9 @@ readLatestImage(callback: AsyncCallback\<Image>): void ...@@ -2340,8 +2354,9 @@ readLatestImage(callback: AsyncCallback\<Image>): void
**示例:** **示例:**
```js ```ts
receiver.readLatestImage((err, img : image.Image) => { import {BusinessError} from '@ohos.base'
receiver.readLatestImage((err : BusinessError, img : image.Image) => {
if(err) { if(err) {
console.log('readLatestImage failed.'); console.log('readLatestImage failed.');
} else { } else {
...@@ -2366,7 +2381,7 @@ readLatestImage(): Promise\<Image> ...@@ -2366,7 +2381,7 @@ readLatestImage(): Promise\<Image>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
receiver.readLatestImage().then((img : image.Image) => { receiver.readLatestImage().then((img : image.Image) => {
console.log('readLatestImage succeeded.'); console.log('readLatestImage succeeded.');
...@@ -2391,8 +2406,9 @@ readNextImage(callback: AsyncCallback\<Image>): void ...@@ -2391,8 +2406,9 @@ readNextImage(callback: AsyncCallback\<Image>): void
**示例:** **示例:**
```js ```ts
receiver.readNextImage((err, img : image.Image) => { import {BusinessError} from '@ohos.base'
receiver.readNextImage((err : BusinessError, img : image.Image) => {
if(err) { if(err) {
console.log('readNextImage failed.'); console.log('readNextImage failed.');
} else { } else {
...@@ -2417,7 +2433,7 @@ readNextImage(): Promise\<Image> ...@@ -2417,7 +2433,7 @@ readNextImage(): Promise\<Image>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
receiver.readNextImage().then((img : image.Image) => { receiver.readNextImage().then((img : image.Image) => {
console.log('readNextImage succeeded.'); console.log('readNextImage succeeded.');
...@@ -2443,7 +2459,7 @@ on(type: 'imageArrival', callback: AsyncCallback\<void>): void ...@@ -2443,7 +2459,7 @@ on(type: 'imageArrival', callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
receiver.on('imageArrival', () => {}) receiver.on('imageArrival', () => {})
``` ```
...@@ -2463,7 +2479,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -2463,7 +2479,7 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
receiver.release(() => {}) receiver.release(() => {})
``` ```
...@@ -2483,7 +2499,7 @@ release(): Promise\<void> ...@@ -2483,7 +2499,7 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
receiver.release().then(() => { receiver.release().then(() => {
console.log('release succeeded.'); console.log('release succeeded.');
...@@ -2517,8 +2533,8 @@ createImageCreator(width: number, height: number, format: number, capacity: numb ...@@ -2517,8 +2533,8 @@ createImageCreator(width: number, height: number, format: number, capacity: numb
**示例:** **示例:**
```js ```ts
var creator : image.ImageCreator = image.createImageCreator(8192, 8, 4, 8); let creator : image.ImageCreator = image.createImageCreator(8192, 8, 4, 8);
``` ```
## ImageCreator<sup>9+</sup> ## ImageCreator<sup>9+</sup>
...@@ -2551,8 +2567,9 @@ dequeueImage(callback: AsyncCallback\<Image>): void ...@@ -2551,8 +2567,9 @@ dequeueImage(callback: AsyncCallback\<Image>): void
**示例:** **示例:**
```js ```ts
creator.dequeueImage((err, img : image.Image) => { import {BusinessError} from '@ohos.base'
creator.dequeueImage((err : BusinessError, img : image.Image) => {
if (err) { if (err) {
console.info('dequeueImage failed.'); console.info('dequeueImage failed.');
} }
...@@ -2576,7 +2593,7 @@ dequeueImage(): Promise\<Image> ...@@ -2576,7 +2593,7 @@ dequeueImage(): Promise\<Image>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
creator.dequeueImage().then((img : image.Image) => { creator.dequeueImage().then((img : image.Image) => {
console.info('dequeueImage succeeded.'); console.info('dequeueImage succeeded.');
...@@ -2602,19 +2619,20 @@ queueImage(interface: Image, callback: AsyncCallback\<void>): void ...@@ -2602,19 +2619,20 @@ queueImage(interface: Image, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base'
creator.dequeueImage().then((img : image.Image) => { creator.dequeueImage().then((img : image.Image) => {
//绘制图片 //绘制图片
img.getComponent(4).then(component : image.Component => { img.getComponent(4).then( (component : image.Component) => {
var bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer);
for (var i = 0; i < bufferArr.length; i += 4) { for (let i = 0; i < bufferArr.length; i += 4) {
bufferArr[i] = 0; //B bufferArr[i] = 0; //B
bufferArr[i + 1] = 0; //G bufferArr[i + 1] = 0; //G
bufferArr[i + 2] = 255; //R bufferArr[i + 2] = 255; //R
bufferArr[i + 3] = 255; //A bufferArr[i + 3] = 255; //A
} }
}) })
creator.queueImage(img, (err) => { creator.queueImage(img, (err : BusinessError) => {
if (err) { if (err) {
console.info('queueImage failed: ' + err); console.info('queueImage failed: ' + err);
} }
...@@ -2646,13 +2664,13 @@ queueImage(interface: Image): Promise\<void> ...@@ -2646,13 +2664,13 @@ queueImage(interface: Image): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
creator.dequeueImage().then((img : image.Image) => { creator.dequeueImage().then((img : image.Image) => {
//绘制图片 //绘制图片
img.getComponent(4).then(component : image.Component => { img.getComponent(4).then(component : image.Component => {
var bufferArr : Uint8Array = new Uint8Array(component.byteBuffer); let bufferArr : Uint8Array = new Uint8Array(component.byteBuffer);
for (var i = 0; i < bufferArr.length; i += 4) { for (let i = 0; i < bufferArr.length; i += 4) {
bufferArr[i] = 0; //B bufferArr[i] = 0; //B
bufferArr[i + 1] = 0; //G bufferArr[i + 1] = 0; //G
bufferArr[i + 2] = 255; //R bufferArr[i + 2] = 255; //R
...@@ -2685,8 +2703,9 @@ on(type: 'imageRelease', callback: AsyncCallback\<void>): void ...@@ -2685,8 +2703,9 @@ on(type: 'imageRelease', callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
creator.on('imageRelease', (err) => { import {BusinessError} from '@ohos.base'
creator.on('imageRelease', (err : BusinessError) => {
if (err) { if (err) {
console.info('on faild' + err); console.info('on faild' + err);
} }
...@@ -2710,8 +2729,9 @@ release(callback: AsyncCallback\<void>): void ...@@ -2710,8 +2729,9 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
creator.release((err) => { import {BusinessError} from '@ohos.base'
creator.release((err : BusinessError) => {
if (err) { if (err) {
console.info('release failed: ' + err); console.info('release failed: ' + err);
} }
...@@ -2734,7 +2754,7 @@ release(): Promise\<void> ...@@ -2734,7 +2754,7 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
creator.release().then(() => { creator.release().then(() => {
console.info('release succeeded'); console.info('release succeeded');
...@@ -2774,8 +2794,9 @@ getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): ...@@ -2774,8 +2794,9 @@ getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>):
**示例:** **示例:**
```js ```ts
img.getComponent(4, (err, component : image.Component) => { import {BusinessError} from '@ohos.base'
img.getComponent(4, (err : BusinessError, component : image.Component) => {
if(err) { if(err) {
console.log('getComponent failed.'); console.log('getComponent failed.');
} else { } else {
...@@ -2806,7 +2827,7 @@ getComponent(componentType: ComponentType): Promise\<Component> ...@@ -2806,7 +2827,7 @@ getComponent(componentType: ComponentType): Promise\<Component>
**示例:** **示例:**
```js ```ts
img.getComponent(4).then((component : image.Component) => { }) img.getComponent(4).then((component : image.Component) => { })
``` ```
...@@ -2828,7 +2849,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -2828,7 +2849,7 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
img.release(() =>{ img.release(() =>{
console.log('release succeeded.'); console.log('release succeeded.');
}) })
...@@ -2852,7 +2873,7 @@ release(): Promise\<void> ...@@ -2852,7 +2873,7 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```ts
import {BusinessError} from '@ohos.base' import {BusinessError} from '@ohos.base'
img.release().then(() =>{ img.release().then(() =>{
console.log('release succeeded.'); console.log('release succeeded.');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册