From 5783b4f95787eb7621f8dde5afa0dcd99bc8c456 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Thu, 7 Jul 2022 16:06:04 +0800 Subject: [PATCH] update docs against 6148 Signed-off-by: wusongqing --- .../reference/apis/js-apis-image.md | 749 +++++++++++++++--- 1 file changed, 630 insertions(+), 119 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-image.md b/en/application-dev/reference/apis/js-apis-image.md index 72f4e34179..7f3465fc3c 100644 --- a/en/application-dev/reference/apis/js-apis-image.md +++ b/en/application-dev/reference/apis/js-apis-image.md @@ -1,13 +1,12 @@ # Image Processing -> **NOTE**
-> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> **NOTE** > -> API version 9 is a canary release for trial use. The APIs of this version may be unstable. +> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import -``` +```js import image from '@ohos.multimedia.image'; ``` @@ -22,8 +21,8 @@ Creates a **PixelMap** object. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | -| colors | ArrayBuffer | Yes | Color array. | -| options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| +| colors | ArrayBuffer | Yes | Color array in BGRA_8888 format. | +| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| **Return value** @@ -34,9 +33,11 @@ Creates a **PixelMap** object. This API uses a promise to return the result. **Example** ```js -image.createPixelMap(Color, opts) - .then((pixelmap) => { - }) +const color = new ArrayBuffer(96); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts) + .then((pixelmap) => { + }) ``` ## image.createPixelMap8+ @@ -51,15 +52,17 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | -------------------------- | -| colors | ArrayBuffer | Yes | Color array. | -| options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties. | +| colors | ArrayBuffer | Yes | Color array in BGRA_8888 format. | +| options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties. | | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.| **Example** ```js -image.createPixelMap(Color, opts, (pixelmap) => { - }) +const color = new ArrayBuffer(96); +let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +image.createPixelMap(color, opts, (pixelmap) => { + }) ``` ## PixelMap7+ @@ -68,9 +71,11 @@ Provides APIs to read or write image pixel map data and obtain image pixel map i ### Attributes -| Name | Type | Readable| Writable| Description | -| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ | -| isEditable7+ | boolean | Yes | No | Whether the image pixel map is editable.
**System capability**: SystemCapability.Multimedia.Image| +**System capability**: SystemCapability.Multimedia.Image + +| Name | Type | Readable| Writable| Description | +| ----------------------- | ------- | ---- | ---- | -------------------------- | +| isEditable7+ | boolean | Yes | No | Whether the image pixel map is editable.| ### readPixelsToBuffer7+ @@ -95,11 +100,11 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u **Example** ```js -pixelmap.readPixelsToBuffer(readBuffer).then(() => { - // Called if the condition is met. - }).catch(error => { - // Called if no condition is met. - }) +pixelmap.readPixelsToBuffer(ReadBuffer).then(() => { + console.log('readPixelsToBuffer succeeded.'); // Called if the condition is met. +}).catch(error => { + console.log('readPixelsToBuffer failed.'); // Called if no condition is met. +}) ``` ### readPixelsToBuffer7+ @@ -120,8 +125,13 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u **Example** ```js -pixelmap.readPixelsToBuffer(readBuffer, () => { - }) +pixelmap.readPixelsToBuffer(ReadBuffer, (err, res) => { + if(err) { + console.log('readPixelsToBuffer failed.'); // Called if no condition is met. + } else { + console.log('readPixelsToBuffer succeeded.'); // Called if the condition is met. + } +}) ``` ### readPixels7+ @@ -147,11 +157,11 @@ Reads image pixel map data in an area. This API uses a promise to return the dat **Example** ```js -pixelmap.readPixels(area).then((data) => { - // Called if the condition is met. - }).catch(error => { - // Called if no condition is met. - }) +pixelmap.readPixels(Area).then((data) => { + console.log('readPixels succeeded.'); // Called if the condition is met. +}).catch(error => { + console.log('readPixels failed.'); // Called if no condition is met. +}) ``` ### readPixels7+ @@ -174,19 +184,17 @@ Reads image pixel map data in an area. This API uses an asynchronous callback to ```js let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } image.createPixelMap(color, opts, (err, pixelmap) => { - if(pixelmap == undefined){ - console.info('createPixelMap failed'); - expect(false).assertTrue(); - done(); - }else{ - const area = { pixels: new ArrayBuffer(8), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} - pixelmap.readPixels(area, () => { - console.info('readPixels success'); - }) - } + if(pixelmap == undefined){ + console.info('createPixelMap failed.'); + } else { + const area = { pixels: new ArrayBuffer(8), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}; + pixelmap.readPixels(area, () => { + console.info('readPixels success'); + }) + } }) ``` @@ -218,16 +226,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } image.createPixelMap(color, opts) .then( pixelmap => { if (pixelmap == undefined) { - console.info('createPixelMap failed'); - expect(false).assertTrue() - done(); + console.info('createPixelMap failed.'); } const area = { pixels: new ArrayBuffer(8), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } - var bufferArr = new Uint8Array(area.pixels); + let bufferArr = new Uint8Array(area.pixels); for (var i = 0; i < bufferArr.length; i++) { bufferArr[i] = i + 1; } @@ -240,11 +246,8 @@ image.createPixelMap(color, opts) region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } }) - }) - .catch(error => { + }).catch(error => { console.log('error: ' + error); - expect().assertFail(); - done(); }) ``` @@ -261,19 +264,23 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | --------- | ------------------------------ | ---- | ------------------------------ | | area | [PositionArea](#positionarea7) | Yes | Area to which the image pixel map data will be written. | -| callback: | AsyncCallback\ | Yes | Callback used to return the operation result. If the operation fails, an error message is returned.| +| callback: | AsyncCallback\ | Yes | Callback used to return the operation result. If the operation fails, `error` contains an error object.| **Example** ```js -pixelmap.writePixels(area, () => { - const readArea = { - pixels: new ArrayBuffer(20), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, - } - }) +pixelmap.writePixels(Area, (error) => { + if (error!=undefined) { + console.info('writePixels failed.'); + } else { + const readArea = { + pixels: new ArrayBuffer(20), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, + } + } +}) ``` ### writeBufferToPixels7+ @@ -299,11 +306,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj **Example** ```js -pixelMap.writeBufferToPixels(colorBuffer).then(() => { +PixelMap.writeBufferToPixels(color).then(() => { console.log("Succeeded in writing data from a buffer to a PixelMap."); }).catch((err) => { console.error("Failed to write data from a buffer to a PixelMap."); -}); +}) ``` ### writeBufferToPixels7+ @@ -324,12 +331,13 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj **Example** ```js -pixelMap.writeBufferToPixels(colorBuffer, function(err) { +PixelMap.writeBufferToPixels(color, function(err) { if (err) { console.error("Failed to write data from a buffer to a PixelMap."); return; - } - console.log("Succeeded in writing data from a buffer to a PixelMap."); + } else { + console.log("Succeeded in writing data from a buffer to a PixelMap."); + } }); ``` @@ -350,7 +358,7 @@ Obtains pixel map information of this image. This API uses a promise to return t **Example** ```js -pixelMap.getImageInfo().then(function(info) { +PixelMap.getImageInfo().then(function(info) { console.log("Succeeded in obtaining the image pixel map information."); }).catch((err) => { console.error("Failed to obtain the image pixel map information."); @@ -374,7 +382,11 @@ Obtains pixel map information of this image. This API uses an asynchronous callb **Example** ```js -pixelmap.getImageInfo((imageInfo) => {}) +pixelmap.getImageInfo((imageInfo) => { + console.log("getImageInfo succeeded."); +}).catch((err) => { + console.error("getImageInfo failed."); +}) ``` ### getBytesNumberPerRow7+ @@ -394,7 +406,9 @@ Obtains the number of bytes per line of the image pixel map. **Example** ```js -rowCount = pixelmap.getBytesNumberPerRow() +image.createPixelMap(clolr, opts, (err,pixelmap) => { + let rowCount = pixelmap.getBytesNumberPerRow(); +}) ``` ### getPixelBytesNumber7+ @@ -414,7 +428,7 @@ Obtains the total number of bytes of the image pixel map. **Example** ```js -pixelBytesNumber = pixelmap.getPixelBytesNumber() +let pixelBytesNumber = pixelmap.getPixelBytesNumber(); ``` ### release7+ @@ -434,8 +448,13 @@ Releases this **PixelMap** object. This API uses a promise to return the result. **Example** ```js - pixelmap.release().then(() => { }) - .catch(error => {}) +image.createPixelMap(color, opts, (pixelmap) => { + pixelmap.release().then(() => { + console.log('release succeeded.'); + }).catch(error => { + console.log('release failed.'); + }) +}) ``` ### release7+ @@ -455,7 +474,13 @@ Releases this **PixelMap** object. This API uses an asynchronous callback to ret **Example** ```js -pixelmap.release(()=>{ }) +image.createPixelMap(color, opts, (pixelmap) => { + pixelmap.release().then(() => { + console.log('release succeeded.'); + }).catch(error => { + console.log('release failed.'); + }) +}) ``` ## image.createImageSource @@ -508,7 +533,7 @@ Creates an **ImageSource** instance based on the file descriptor. **Example** ```js -const imageSourceApi = image.createImageSource(0) +const imageSourceApi = image.createImageSource(0); ``` ## ImageSource @@ -517,9 +542,11 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour ### Attributes +**System capability**: SystemCapability.Multimedia.Image + | Name | Type | Readable| Writable| Description | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| supportedFormats | Array\ | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.
**System capability**: SystemCapability.Multimedia.Image| +| supportedFormats | Array\ | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.| ### getImageInfo @@ -539,7 +566,13 @@ Obtains information about an image with the specified index. This API uses an as **Example** ```js -imageSourceApi.getImageInfo(0,(error, imageInfo) => {}) +imageSourceApi.getImageInfo(0,(error, imageInfo) => { + if(error) { + console.log('getImageInfo failed.'); + } else { + console.log('getImageInfo succeeded.'); + } +}) ``` ### getImageInfo @@ -559,7 +592,11 @@ Obtains information about this image. This API uses an asynchronous callback to **Example** ```js -imageSourceApi.getImageInfo(imageInfo => {}) +imageSourceApi.getImageInfo(imageInfo => { + console.log('getImageInfo succeeded.'); +}).catch(error => { + console.log('getImageInfo failed.'); +}) ``` ### getImageInfo @@ -586,8 +623,11 @@ Obtains information about an image with the specified index. This API uses a pro ```js imageSourceApi.getImageInfo(0) - .then(imageInfo => {}) - .catch(error => {}) + .then(imageInfo => { + console.log('getImageInfo succeeded.'); + }).catch(error => { + console.log('getImageInfo failed.'); + }) ``` ### getImageProperty7+ @@ -615,8 +655,11 @@ Obtains the value of a property with the specified index in this image. This API ```js imageSourceApi.getImageProperty("BitsPerSample") - .then(data => {}) - .catch(error => {}) + .then(data => { + console.log('getImageProperty succeeded.'); + }).catch(error => { + console.log('getImageProperty failed.'); + }) ``` ### getImageProperty7+ @@ -637,7 +680,13 @@ Obtains the value of a property with the specified index in this image. This API **Example** ```js -imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {}) +imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { + if(error) { + console.log('getImageProperty failed.'); + } else { + console.log('getImageProperty succeeded.'); + } +}) ``` ### getImageProperty7+ @@ -659,7 +708,13 @@ Obtains the value of a property in this image. This API uses an asynchronous cal **Example** ```js -imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {}) +imageSourceApi.getImageProperty("BitsPerSample",Property,(error,data) => { + if(error) { + console.log('getImageProperty failed.'); + } else { + console.log('getImageProperty succeeded.'); + } +}) ``` ### createPixelMap7+ @@ -685,8 +740,11 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses **Example** ```js -imageSourceApi.createPixelMap().then(pixelmap => {}) - .catch(error => {}) +imageSourceApi.createPixelMap().then(pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### createPixelMap7+ @@ -706,7 +764,11 @@ Creates a **PixelMap** object based on the default parameters. This API uses an **Example** ```js -imageSourceApi.createPixelMap(pixelmap => {}) +imageSourceApi.createPixelMap(pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### createPixelMap7+ @@ -727,7 +789,11 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses **Example** ```js -imageSourceApi.createPixelMap(decodingOptions, pixelmap => {}) +imageSourceApi.createPixelMap(decodingOptions, pixelmap => { + console.log('createPixelMap succeeded.'); +}).catch(error => { + console.log('createPixelMap failed.'); +}) ``` ### release @@ -747,7 +813,11 @@ Releases this **ImageSource** instance. This API uses an asynchronous callback t **Example** ```js -imageSourceApi.release(() => {}) +imageSourceApi.release(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -767,7 +837,11 @@ Releases this **ImageSource** instance. This API uses a promise to return the re **Example** ```js -imageSourceApi.release().then(()=>{ }).catch(error => {}) +imageSourceApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## image.createImagePacker @@ -796,9 +870,11 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must ### Attributes -| Name | Type | Readable| Writable| Description | -| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | -| supportedFormats | Array\ | Yes | No | Supported image format, which can be jpeg.
**System capability**: SystemCapability.Multimedia.Image| +**System capability**: SystemCapability.Multimedia.Image + +| Name | Type | Readable| Writable| Description | +| ---------------- | -------------- | ---- | ---- | -------------------------- | +| supportedFormats | Array\ | Yes | No | Supported image format, which can be jpeg.| ### packing @@ -814,13 +890,13 @@ Packs an image. This API uses an asynchronous callback to return the result. | -------- | ---------------------------------- | ---- | ---------------------------------- | | source | [ImageSource](#imagesource) | Yes | Image to pack. | | option | [PackingOption](#packingoption) | Yes | Option for image packing. | -| callback | AsyncCallback\ | Yes | Callback used to return the packed data.| +| callback | AsyncCallback\ | Yes | Callback used to return the packed data.| **Example** ```js -let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(imageSourceApi, packOpts, data => {}) +let packOpts = { format:"image/jpeg", quality:98 }; +imagePackerApi.packing(ImageSourceApi, packOpts, data => {}) ``` ### packing @@ -848,9 +924,12 @@ Packs an image. This API uses a promise to return the result. ```js let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(imageSourceApi, packOpts) - .then( data => { }) - .catch(error => {}) +imagePackerApi.packing(ImageSourceApi, packOpts) + .then( data => { + console.log('packing succeeded.'); + }).catch(error => { + console.log('packing failed.'); + }) ``` ### packing8+ @@ -873,7 +952,11 @@ Packs an image. This API uses an asynchronous callback to return the result. ```js let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(pixelMapApi, packOpts, data => {}) +imagePackerApi.packing(PixelMapApi, packOpts, data => { + console.log('packing succeeded.'); +}).catch(error => { + console.log('packing failed.'); +}) ``` ### packing8+ @@ -886,10 +969,10 @@ Packs an image. This API uses a promise to return the result. **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------------------------------- | ---- | -------------- | +| Name| Type | Mandatory| Description | +| ------ | ------------------------------- | ---- | ------------------ | | source | [PixelMap](#pixelmap) | Yes | **PixelMap** object to pack.| -| option | [PackingOption](#packingoption) | Yes | Option for image packing.| +| option | [PackingOption](#packingoption) | Yes | Option for image packing. | **Return value** @@ -901,9 +984,12 @@ Packs an image. This API uses a promise to return the result. ```js let packOpts = { format:["image/jpeg"], quality:98 } -imagePackerApi.packing(pixelMapApi, packOpts) - .then( data => { }) - .catch(error => {}) +imagePackerApi.packing(PixelMapApi, packOpts) + .then( data => { + console.log('packing succeeded.'); + }).catch(error => { + console.log('packing failed.'); + }) ``` ### release @@ -923,7 +1009,11 @@ Releases this **ImagePacker** instance. This API uses an asynchronous callback t **Example** ```js -imagePackerApi.release(()=>{}) +imagePackerApi.release(()=>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ### release @@ -943,8 +1033,390 @@ Releases this **ImagePacker** instance. This API uses a promise to return the re **Example** ```js - imagePackerApi.release().then(()=>{ - }).catch((error)=>{}) +imagePackerApi.release().then(()=>{ + console.log('release succeeded.'); +}).catch((error)=>{ + console.log('release failed.'); +}) +``` + +## image.createImageReceiver9+ + +createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver + +Create an **ImageReceiver** instance by specifying the image width, height, format, and capacity. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ---------------------- | +| width | number | Yes | Default image width. | +| height | number | Yes | Default image height. | +| format | number | Yes | Image format. | +| capacity | number | Yes | Maximum number of images that can be accessed at the same time.| + +**Return value** + +| Type | Description | +| -------------------------------- | --------------------------------------- | +| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.| + +**Example** + +```js +var receiver = image.createImageReceiver(8192, 8, 4, 8); +``` + +## ImageReceiver9+ + +Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance. + +Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance. + +### Attributes + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +| Name | Type | Readable| Writable| Description | +| --------------------- | ---------------------------- | ---- | ---- | ------------------ | +| size9+ | [Size](#size) | Yes | No | Image size. | +| capacity9+ | number | Yes | No | Maximum number of images that can be accessed at the same time.| +| format9+ | [ImageFormat](#imageformat9) | Yes | No | Image format. | + +### getReceivingSurfaceId9+ + +getReceivingSurfaceId(callback: AsyncCallback\): void + +Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the surface ID.| + +**Example** + +```js + receiver.getReceivingSurfaceId((err, id) => { + if(err) { + console.log('getReceivingSurfaceId failed.'); + } else { + console.log('getReceivingSurfaceId succeeded.'); + } +}); +``` + +### getReceivingSurfaceId9+ + +getReceivingSurfaceId(): Promise\ + +Obtains a surface ID for the camera or other components. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Return value** + +| Type | Description | +| ---------------- | -------------------- | +| Promise\ | Promise used to return the surface ID.| + +**Example** + +```js +receiver.getReceivingSurfaceId().then( id => { + console.log('getReceivingSurfaceId succeeded.'); +}).catch(error => { + console.log('getReceivingSurfaceId failed.'); +}) +``` + +### readLatestImage9+ + +readLatestImage(callback: AsyncCallback\): void + +Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the latest image.| + +**Example** + +```js +receiver.readLatestImage((err, img) => { + if(err) { + console.log('readLatestImage failed.'); + } else { + console.log('readLatestImage succeeded.'); + } +}); +``` + +### readLatestImage9+ + +readLatestImage(): Promise\ + +Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Return value** + +| Type | Description | +| ------------------------- | ------------------ | +| Promise<[Image](#image8)> | Promise used to return the latest image.| + +**Example** + +```js +receiver.readLatestImage().then(img => { + console.log('readLatestImage succeeded.'); +}).catch(error => { + console.log('readLatestImage failed.'); +}) +``` + +### readNextImage9+ + +readNextImage(callback: AsyncCallback\): void + +Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the next image.| + +**Example** + +```js +receiver.readNextImage((err, img) => { + if(err) { + console.log('readNextImage failed.'); + } else { + console.log('readNextImage succeeded.'); + } +}); +``` + +### readNextImage9+ + +readNextImage(): Promise\ + +Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Return value** + +| Type | Description | +| ------------------------- | -------------------- | +| Promise<[Image](#image9)> | Promise used to return the next image.| + +**Example** + +```js +receiver.readNextImage().then(img => { + console.log('readNextImage succeeded.'); +}).catch(error => { + console.log('readNextImage failed.'); +}) +``` + +### on('imageArrival')9+ + +on(type: 'imageArrival', callback: AsyncCallback\): void + +Listens for image arrival events. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------ | +| type | string | Yes | Type of event to listen for. The value is fixed at **imageArrival**, which is triggered when an image is received.| +| callback | AsyncCallback\ | Yes | Callback invoked for the event. | + +**Example** + +```js +receiver.on('imageArrival', () => {}) +``` + +### release9+ + +release(callback: AsyncCallback\): void + +Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +receiver.release(() => {}) +``` + +### release9+ + +release(): Promise\ + +Releases this **ImageReceiver** instance. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +**Return value** + +| Type | Description | +| -------------- | ------------------ | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +receiver.release().then(() => { + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) +``` + +## Image9+ + +Provides APIs for basic image operations, including obtaining image information and reading and writing image data. An **Image** instance is returned when [readNextImage](#readnextimage9) and [readLatestImage](#readlatestimage9) are called. + +### Attributes + +**System capability**: SystemCapability.Multimedia.Image.Core + +| Name | Type | Readable| Writable| Description | +| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- | +| clipRect9+ | [Region](#region7) | Yes | Yes | Image area to be cropped. | +| size9+ | [Size](#size) | Yes | No | Image size. | +| format9+ | number | Yes | No | Image format. For details, see [PixelMapFormat](#pixelmapformat7).| + +### getComponent9+ + +getComponent(componentType: ComponentType, callback: AsyncCallback\): void + +Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Image.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------- | --------------------------------------- | ---- | -------------------- | +| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image. | +| callback | AsyncCallback<[Component](#component9)> | Yes | Callback used to return the component buffer.| + +**Example** + +```js +img.getComponent(4, (err, component) => { + if(err) { + console.log('getComponent failed.'); + } else { + console.log('getComponent succeeded.'); + } +}) +``` + +### getComponent9+ + +getComponent(componentType: ComponentType): Promise\ + +Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Image.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------- | -------------------------------- | ---- | ---------------- | +| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image.| + +**Return value** + +| Type | Description | +| --------------------------------- | --------------------------------- | +| Promise<[Component](#component9)> | Promise used to return the component buffer.| + +**Example** + +```js +img.getComponent(4).then(component => { }) +``` + +### release9+ + +release(callback: AsyncCallback\): void + +Releases this **Image** instance. This API uses an asynchronous callback to return the result. + +The corresponding resources must be released before another image arrives. + +**System capability**: SystemCapability.Multimedia.Image.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +img.release(() =>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) +``` + +### release9+ + +release(): Promise\ + +Releases this **Image** instance. This API uses a promise to return the result. + +The corresponding resources must be released before another image arrives. + +**System capability**: SystemCapability.Multimedia.Image.Core + +**Return value** + +| Type | Description | +| -------------- | --------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +img.release().then(() =>{ + console.log('release succeeded.'); +}).catch(error => { + console.log('release failed.'); +}) ``` ## PositionArea7+ @@ -957,7 +1429,7 @@ Describes area information in an image. | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | pixels | ArrayBuffer | Yes | No | Pixels of the image. | | offset | number | Yes | No | Offset for data reading. | -| stride | number | Yes | No | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4. | +| stride | number | Yes | No | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4. | | region | [Region](#region7) | Yes | No | Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.| ## ImageInfo @@ -983,7 +1455,7 @@ Describes the size of an image. ## PixelMapFormat7+ -Enumerates pixel map formats. +Enumerates the pixel formats of images. **System capability**: SystemCapability.Multimedia.Image @@ -995,7 +1467,7 @@ Enumerates pixel map formats. ## AlphaType9+ -Enumerates alpha types. +Enumerates the alpha types of images. **System capability**: SystemCapability.Multimedia.Image @@ -1008,7 +1480,7 @@ Enumerates alpha types. ## ScaleMode9+ -Enumerates scale modes. +Enumerates the scale modes of images. **System capability**: SystemCapability.Multimedia.Image @@ -1019,19 +1491,21 @@ Enumerates scale modes. ## InitializationOptions8+ +Defines pixel map initialization options. + **System capability**: SystemCapability.Multimedia.Image -| Name | Type | Readable| Writable| Description | -| ----------- | ---------------------------------- | ---- | ---- | -------------- | -| alphaType9+ | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. | -| editable | boolean | Yes | Yes | Whether the image is editable. | -| pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | -| scaleMode9+ | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. | -| size | [Size](#size) | Yes | Yes | Image size.| +| Name | Type | Readable| Writable| Description | +| ---------------------- | ---------------------------------- | ---- | ---- | -------------- | +| alphaType9+ | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. | +| editable | boolean | Yes | Yes | Whether the image is editable. | +| pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | +| scaleMode9+ | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. | +| size | [Size](#size) | Yes | Yes | Image size.| ## DecodingOptions7+ -Describes the decoding options. +Defines image decoding options. **System capability**: SystemCapability.Multimedia.Image @@ -1043,7 +1517,7 @@ Describes the decoding options. | desiredSize | [Size](#size) | Yes | Yes | Expected output size. | | desiredRegion | [Region](#region7) | Yes | Yes | Region to decode. | | desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format for decoding.| -| index | numer | Yes | Yes | Index of the image to decode. | +| index | number | Yes | Yes | Index of the image to decode. | ## Region7+ @@ -1066,7 +1540,7 @@ Describes the option for image packing. | Name | Type | Readable| Writable| Description | | ------- | ------ | ---- | ---- | -------------- | | format | string | Yes | Yes | Format of the packed image. | -| quality | number | Yes | Yes | Quality of the packed image.| +| quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.| ## GetImagePropertyOptions7+ @@ -1095,3 +1569,40 @@ Describes the exchangeable image file format (Exif) information of an image. | GPS_LONGITUDE | "GPSLongitude" | Image longitude. | | GPS_LATITUDE_REF | "GPSLatitudeRef" | Latitude reference, for example, N or S.| | GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E.| + +## ImageFormat9+ + +Enumerates the image formats. + +**System capability**: SystemCapability.Multimedia.Image.Core + +| Name | Default Value| Description | +| ------------ | ------ | -------------------- | +| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.| +| JPEG | 2000 | JPEG encoding format. | + +## ComponentType9+ + +Enumerates the color component types of images. + +**System capability**: SystemCapability.Multimedia.Image.ImageReceiver + +| Name | Default Value| Description | +| ----- | ------ | ----------- | +| YUV_Y | 1 | Luminance component. | +| YUV_U | 2 | Chrominance component. | +| YUV_V | 3 | Chrominance component. | +| JPEG | 4 | JPEG type.| + +## Component9+ + +Describes the color components of an image. + +**System capability**: SystemCapability.Multimedia.Image.Core + +| Name | Type | Readable| Writable| Description | +| ------------- | -------------------------------- | ---- | ---- | ------------ | +| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. | +| rowStride | number | Yes | No | Row stride. | +| pixelStride | number | Yes | No | Pixel stride. | +| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| -- GitLab