提交 4b7b644d 编写于 作者: W wusongqing

update image against 6318+6600+6647+6693+6876+6945+7095+7160+7531+7690

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 57f7003c
# Image Processing # Image Processing
The **Image** module provides APIs for image processing. You can use the APIs to create a **PixelMap** object with specified properties or read image pixel data (even in an area).
> **NOTE** > **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. > 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.
...@@ -11,11 +13,12 @@ import image from '@ohos.multimedia.image'; ...@@ -11,11 +13,12 @@ import image from '@ohos.multimedia.image';
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap> createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
Creates a **PixelMap** object. This API uses a promise to return the result. Creates a **PixelMap** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -34,7 +37,7 @@ Creates a **PixelMap** object. This API uses a promise to return the result. ...@@ -34,7 +37,7 @@ Creates a **PixelMap** object. This API uses a promise to return the result.
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts) image.createPixelMap(color, opts)
.then((pixelmap) => { .then((pixelmap) => {
...@@ -47,7 +50,7 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As ...@@ -47,7 +50,7 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As
Creates a **PixelMap** object. This API uses an asynchronous callback to return the result. Creates a **PixelMap** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -61,10 +64,15 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return ...@@ -61,10 +64,15 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => { image.createPixelMap(color, opts, (error, pixelmap) => {
}) if(error) {
console.log('Failed to create pixelmap.');
} else {
console.log('Succeeded in creating pixelmap.');
}
})
``` ```
## PixelMap<sup>7+</sup> ## PixelMap<sup>7+</sup>
...@@ -73,11 +81,11 @@ Provides APIs to read or write image pixel map data and obtain image pixel map i ...@@ -73,11 +81,11 @@ Provides APIs to read or write image pixel map data and obtain image pixel map i
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------------------- | ------- | ---- | ---- | -------------------------- | | ---------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | Yes | No | Whether the image pixel map is editable.| | isEditable | boolean | Yes | No | Whether the image pixel map is editable.|
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -85,24 +93,24 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> ...@@ -85,24 +93,24 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses a promise to return the result. Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------- | ---- | ------------------------------------------------------------ | | ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst | ArrayBuffer | Yes | Buffer to which the image pixel map data will be written.| | dst | ArrayBuffer | Yes | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling **getPixelBytesNumber**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------------------------- | | -------------- | ----------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.| | Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const readBuffer = new ArrayBuffer(400); const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(readBuffer).then(() => {
console.log('Succeeded in reading image pixel data.'); // Called if the condition is met. console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
}).catch(error => { }).catch(error => {
...@@ -116,19 +124,19 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -116,19 +124,19 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses an asynchronous callback to return the result. Reads image pixel map data and writes the data to an **ArrayBuffer**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst | ArrayBuffer | Yes | Buffer to which the image pixel map data will be written.| | dst | ArrayBuffer | Yes | Buffer to which the image pixel map data will be written. The buffer size is obtained by calling **getPixelBytesNumber**.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the operation result. If the operation fails, an error message is returned. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned. |
**Example** **Example**
```js ```js
const readBuffer = new ArrayBuffer(400); const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => { pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
if(err) { if(err) {
console.log('Failed to read image pixel data.'); // Called if no condition is met. console.log('Failed to read image pixel data.'); // Called if no condition is met.
...@@ -144,7 +152,7 @@ readPixels(area: PositionArea): Promise\<void> ...@@ -144,7 +152,7 @@ readPixels(area: PositionArea): Promise\<void>
Reads image pixel map data in an area. This API uses a promise to return the data read. Reads image pixel map data in an area. This API uses a promise to return the data read.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -156,7 +164,7 @@ Reads image pixel map data in an area. This API uses a promise to return the dat ...@@ -156,7 +164,7 @@ Reads image pixel map data in an area. This API uses a promise to return the dat
| Type | Description | | Type | Description |
| :------------- | :-------------------------------------------------- | | :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.| | Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
...@@ -175,20 +183,20 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -175,20 +183,20 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
Reads image pixel map data in an area. This API uses an asynchronous callback to return the data read. Reads image pixel map data in an area. This API uses an asynchronous callback to return the data read.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ------------------------------ | | -------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#positionarea7) | Yes | Area from which the image pixel map data will be read. | | area | [PositionArea](#positionarea7) | Yes | Area from which the image pixel map data will be read. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the operation result. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => { image.createPixelMap(color, opts, (err, pixelmap) => {
if(pixelmap == undefined){ if(pixelmap == undefined){
...@@ -211,7 +219,7 @@ writePixels(area: PositionArea): Promise\<void> ...@@ -211,7 +219,7 @@ writePixels(area: PositionArea): Promise\<void>
Writes image pixel map data to an area. This API uses a promise to return the operation result. Writes image pixel map data to an area. This API uses a promise to return the operation result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -223,13 +231,13 @@ Writes image pixel map data to an area. This API uses a promise to return the op ...@@ -223,13 +231,13 @@ Writes image pixel map data to an area. This API uses a promise to return the op
| Type | Description | | Type | Description |
| :------------- | :-------------------------------------------------- | | :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.| | Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts) image.createPixelMap(color, opts)
.then( pixelmap => { .then( pixelmap => {
...@@ -265,21 +273,21 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -265,21 +273,21 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
Writes image pixel map data to an area. This API uses an asynchronous callback to return the operation result. Writes image pixel map data to an area. This API uses an asynchronous callback to return the operation result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------ | ---- | ------------------------------ | | --------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#positionarea7) | Yes | Area to which the image pixel map data will be written. | | area | [PositionArea](#positionarea7) | Yes | Area to which the image pixel map data will be written. |
| callback: | AsyncCallback\<void> | Yes | Callback used to return the operation result. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const area = new ArrayBuffer(400); const area = new ArrayBuffer(400);
pixelmap.writePixels(area, (error) => { pixelmap.writePixels(area, (error) => {
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 {
const readArea = { const readArea = {
...@@ -298,7 +306,7 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void> ...@@ -298,7 +306,7 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses a promise to return the result. Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -310,14 +318,14 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj ...@@ -310,14 +318,14 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
| Type | Description | | Type | Description |
| -------------- | ----------------------------------------------- | | -------------- | ----------------------------------------------- |
| Promise\<void> | Promise used to return the operation result. If the operation fails, an error message is returned.| | Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400); const pixelMap = new ArrayBuffer(400);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
pixelMap.writeBufferToPixels(color).then(() => { pixelMap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((err) => {
...@@ -331,21 +339,21 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -331,21 +339,21 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses an asynchronous callback to return the result. Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------ | | -------- | -------------------- | ---- | ------------------------------ |
| src | ArrayBuffer | Yes | Buffer from which the image data will be read. | | src | ArrayBuffer | Yes | Buffer from which the image data will be read. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the operation result. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96);\ const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400); const pixelMap = new ArrayBuffer(400);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
pixelMap.writeBufferToPixels(color, function(err) { pixelMap.writeBufferToPixels(color, function(err) {
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.");
...@@ -362,7 +370,7 @@ getImageInfo(): Promise\<ImageInfo> ...@@ -362,7 +370,7 @@ getImageInfo(): Promise\<ImageInfo>
Obtains pixel map information of this image. This API uses a promise to return the information. Obtains pixel map information of this image. This API uses a promise to return the information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Return value** **Return value**
...@@ -387,7 +395,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -387,7 +395,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
Obtains pixel map information of this image. This API uses an asynchronous callback to return the information. Obtains pixel map information of this image. This API uses an asynchronous callback to return the information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
...@@ -399,7 +407,7 @@ Obtains pixel map information of this image. This API uses an asynchronous callb ...@@ -399,7 +407,7 @@ Obtains pixel map information of this image. This API uses an asynchronous callb
```js ```js
pixelmap.getImageInfo((imageInfo) => { pixelmap.getImageInfo((imageInfo) => {
console.log("Succeeded in obtaining the image pixel map information.."); console.log("Succeeded in obtaining the image pixel map information.");
}) })
``` ```
...@@ -407,21 +415,21 @@ pixelmap.getImageInfo((imageInfo) => { ...@@ -407,21 +415,21 @@ pixelmap.getImageInfo((imageInfo) => {
getBytesNumberPerRow(): number getBytesNumberPerRow(): number
Obtains the number of bytes per line of the image pixel map. Obtains the number of bytes per row of this image pixel map.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| number | Number of bytes per line.| | number | Number of bytes per row.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err,pixelmap) => { image.createPixelMap(color, opts, (err,pixelmap) => {
let rowCount = pixelmap.getBytesNumberPerRow(); let rowCount = pixelmap.getBytesNumberPerRow();
...@@ -432,9 +440,9 @@ image.createPixelMap(color, opts, (err,pixelmap) => { ...@@ -432,9 +440,9 @@ image.createPixelMap(color, opts, (err,pixelmap) => {
getPixelBytesNumber(): number getPixelBytesNumber(): number
Obtains the total number of bytes of the image pixel map. Obtains the total number of bytes of this image pixel map.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Return value** **Return value**
...@@ -448,25 +456,410 @@ Obtains the total number of bytes of the image pixel map. ...@@ -448,25 +456,410 @@ Obtains the total number of bytes of the image pixel map.
let pixelBytesNumber = pixelmap.getPixelBytesNumber(); let pixelBytesNumber = pixelmap.getPixelBytesNumber();
``` ```
### getDensity<sup>9+</sup>
getDensity():number
Obtains the density of this image pixel map.
**System capability**: SystemCapability.Multimedia.Image.Core
**Return value**
| Type | Description |
| ------ | --------------- |
| number | Density of the image pixel map.|
**Example**
```js
let getDensity = pixelmap.getDensity();
```
### opacity<sup>9+</sup>
opacity(rate: number, callback: AsyncCallback\<void>): void
Sets an opacity rate for this image pixel map. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------ |
| rate | number | Yes | Opacity rate to set. The value ranges from 0 to 1. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.opacity(0.5);
}
```
### opacity<sup>9+</sup>
opacity(rate: number): Promise\<void>
Sets an opacity rate for this image pixel map. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | --------------------------- |
| rate | number | Yes | Opacity rate to set. The value ranges from 0 to 1.|
**Return value**
| Type | Description |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.opacity(0.5);
}
```
### createAlphaPixelmap<sup>9+</sup>
createAlphaPixelmap(): Promise\<PixelMap>
Creates a **PixelMap** object that contains only the alpha channel information. This object can be used for the shadow effect. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Return value**
| Type | Description |
| -------------------------------- | --------------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
**Example**
```js
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {
if (alphaPixelMap == undefined) {
console.info('Failed to obtain new pixel map.');
} else {
console.info('Succeed in obtaining new pixel map.');
}
})
```
### createAlphaPixelmap<sup>9+</sup>
createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
Creates a **PixelMap** object that contains only the alpha channel information. This object can be used for the shadow effect. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------ |
| callback | AsyncCallback\<PixelMap> | Yes | Callback used to return the **PixelMap** object.|
**Example**
```js
let pixelMap = await imageSource.createPixelMap();
if (pixelMap != undefined) {
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {
console.info('Failed to obtain new pixel map.');
})
} else {
console.info('Succeed in obtaining new pixel map.');
}
```
### scale<sup>9+</sup>
scale(x: number, y: number, callback: AsyncCallback\<void>): void
Scales this image based on the input width and height. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------- |
| x | number | Yes | Scaling ratio of the width.|
| y | number | Yes | Scaling ratio of the height.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned. |
**Example**
```js
async function () {
await pixelMap.scale(2.0, 1.0);
}
```
### scale<sup>9+</sup>
scale(x: number, y: number): Promise\<void>
Scales this image based on the input width and height. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- |
| x | number | Yes | Scaling ratio of the width.|
| y | number | Yes | Scaling ratio of the height.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
async function () {
await pixelMap.scale(2.0, 1.0);
}
```
### translate<sup>9+</sup>
translate(x: number, y: number, callback: AsyncCallback\<void>): void
Translates this image based on the input coordinates. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ----------------------------- |
| x | number | Yes | X coordinate to translate. |
| y | number | Yes | Y coordinate to translate. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.translate(3.0, 1.0);
}
```
### translate<sup>9+</sup>
translate(x: number, y: number): Promise\<void>
Translates this image based on the input coordinates. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------- |
| x | number | Yes | X coordinate to translate.|
| y | number | Yes | Y coordinate to translate.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
async function () {
await pixelMap.translate(3.0, 1.0);
}
```
### rotate<sup>9+</sup>
rotate(angle: number, callback: AsyncCallback\<void>): void
Rotates this image based on the input angle. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ----------------------------- |
| angle | number | Yes | Angle to rotate. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.rotate(90.0);
}
```
### rotate<sup>9+</sup>
rotate(angle: number): Promise\<void>
Rotates this image based on the input angle. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------------------------- |
| angle | number | Yes | Angle to rotate. |
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
async function () {
await pixelMap.rotate(90.0);
}
```
### flip<sup>9+</sup>
flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void
Flips this image horizontally or vertically, or both. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------- | ---- | ----------------------------- |
| horizontal | boolean | Yes | Whether to flip the image horizontally. |
| vertical | boolean | Yes | Whether to flip the image vertically. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.flip(false, true);
}
```
### flip<sup>9+</sup>
flip(horizontal: boolean, vertical: boolean): Promise\<void>
Flips this image horizontally or vertically, or both. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------- | ---- | --------- |
| horizontal | boolean | Yes | Whether to flip the image horizontally.|
| vertical | boolean | Yes | Whether to flip the image vertically.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
async function () {
await pixelMap.flip(false, true);
}
```
### crop<sup>9+</sup>
crop(region: Region, callback: AsyncCallback\<void>): void
Crops this image based on the input size. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ----------------------------- |
| region | [Region](#region7) | Yes | Size of the image after cropping. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation fails, an error message is returned.|
**Example**
```js
async function () {
await pixelMap.crop(3x3);
}
```
### crop<sup>9+</sup>
crop(region: Region): Promise\<void>
Crops this image based on the input size. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------ | ---- | ----------- |
| region | [Region](#region7) | Yes | Size of the image after cropping.|
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
async function () {
await pixelMap.crop(3x3);
}
```
### release<sup>7+</sup> ### release<sup>7+</sup>
release():Promise\<void> release():Promise\<void>
Releases this **PixelMap** object. This API uses a promise to return the result. Releases this **PixelMap** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------ | | -------------- | ------------------------------- |
| Promise\<void> | Promise used to return the operation result.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => { image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => { pixelmap.release().then(() => {
...@@ -483,25 +876,23 @@ release(callback: AsyncCallback\<void>): void ...@@ -483,25 +876,23 @@ release(callback: AsyncCallback\<void>): void
Releases this **PixelMap** object. This API uses an asynchronous callback to return the result. Releases this **PixelMap** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------ | | -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | Yes | Callback used to return the operation result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Unit8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => { image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => { pixelmap.release().then(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
}).catch(error => {
console.log('Failed to release pixelmap object.');
}) })
}) })
``` ```
...@@ -512,7 +903,7 @@ createImageSource(uri: string): ImageSource ...@@ -512,7 +903,7 @@ createImageSource(uri: string): ImageSource
Creates an **ImageSource** instance based on the URI. Creates an **ImageSource** instance based on the URI.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -533,18 +924,45 @@ let path = this.context.getApplicationContext().fileDirs + "test.jpg"; ...@@ -533,18 +924,45 @@ let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path); const imageSourceApi = image.createImageSource(path);
``` ```
## image.createImageSource<sup>9+</sup>
createImageSource(uri: string, options: SourceOptions): ImageSource
Creates an **ImageSource** instance based on the URI.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ----------------------------------- |
| uri | string | Yes | Image path. Currently, only the application sandbox path is supported. |
| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image index and default property value.|
**Return value**
| Type | Description |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
**Example**
```js
const imageSourceApi = image.createImageSource('/sdcard/test.jpg');
```
## image.createImageSource<sup>7+</sup> ## image.createImageSource<sup>7+</sup>
createImageSource(fd: number): ImageSource createImageSource(fd: number): ImageSource
Creates an **ImageSource** instance based on the file descriptor. Creates an **ImageSource** instance based on the file descriptor.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------- | | ------ | ------ | ---- | ------------- |
| fd | number | Yes | File descriptor.| | fd | number | Yes | File descriptor.|
**Return value** **Return value**
...@@ -559,13 +977,144 @@ Creates an **ImageSource** instance based on the file descriptor. ...@@ -559,13 +977,144 @@ Creates an **ImageSource** instance based on the file descriptor.
const imageSourceApi = image.createImageSource(0); const imageSourceApi = image.createImageSource(0);
``` ```
## image.createImageSource<sup>9+</sup>
createImageSource(fd: number, options: SourceOptions): ImageSource
Creates an **ImageSource** instance based on the file descriptor.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ----------------------------------- |
| fd | number | Yes | File descriptor. |
| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image index and default property value.|
**Return value**
| Type | Description |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
**Example**
```js
const imageSourceApi = image.createImageSource(fd);
```
## image.createImageSource<sup>9+</sup>
createImageSource(buf: ArrayBuffer): ImageSource
Creates an **ImageSource** instance based on the buffer.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------- | ---- | ---------------- |
| buf | ArrayBuffer | Yes | Array of image buffers.|
**Example**
```js
const buf = new ArrayBuffer(96);
const imageSourceApi = image.createImageSource(buf);
```
## image.createImageSource<sup>9+</sup>
createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource
Creates an **ImageSource** instance based on the buffer.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------------------------------- | ---- | ------------------------------------ |
| buf | ArrayBuffer | Yes | Array of image buffers. |
| options | [SourceOptions](#sourceoptions9) | Yes | Image properties, including the image index and default property value.|
**Return value**
| Type | Description |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
**Example**
```js
const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);
```
## image.CreateIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffer.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------| ---- | ----------|
| buf | ArrayBuffer | Yes | Incremental data.|
**Return value**
| Type | Description |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
**Example**
```js
const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf);
```
## image.CreateIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffer.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ------------------------------------ |
| buf | ArrayBuffer | Yes | Incremental data. |
| options | [SourceOptions](#sourceoptions9) | No | Image properties, including the image index and default property value.|
**Return value**
| Type | Description |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns undefined otherwise.|
**Example**
```js
const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf);
```
## ImageSource ## ImageSource
Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use **createImageSource** to create an **ImageSource** instance. Provides APIs to obtain image information. Before calling any API in **ImageSource**, you must use **createImageSource** to create an **ImageSource** instance.
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
...@@ -577,7 +1126,7 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void ...@@ -577,7 +1126,7 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
Obtains information about an image with the specified index. This API uses an asynchronous callback to return the information. Obtains information about an image with the specified index. This API uses an asynchronous callback to return the information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -604,7 +1153,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -604,7 +1153,7 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
Obtains information about this image. This API uses an asynchronous callback to return the information. Obtains information about this image. This API uses an asynchronous callback to return the information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -626,7 +1175,7 @@ getImageInfo(index?: number): Promise\<ImageInfo> ...@@ -626,7 +1175,7 @@ getImageInfo(index?: number): Promise\<ImageInfo>
Obtains information about an image with the specified index. This API uses a promise to return the image information. Obtains information about an image with the specified index. This API uses a promise to return the image information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -657,7 +1206,7 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string ...@@ -657,7 +1206,7 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string
Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. Obtains the value of a property with the specified index in this image. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -668,8 +1217,8 @@ Obtains the value of a property with the specified index in this image. This API ...@@ -668,8 +1217,8 @@ Obtains the value of a property with the specified index in this image. This API
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ------------------------------------------------------------ | | ---------------- | ----------------------------------------------------------------- |
| Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.| | Promise\<string> | Promise used to return the property value. If the operation fails, the default value is returned.|
**Example** **Example**
...@@ -687,7 +1236,7 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void ...@@ -687,7 +1236,7 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void
Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result. Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -714,14 +1263,14 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa ...@@ -714,14 +1263,14 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
Obtains the value of a property in this image. This API uses an asynchronous callback to return the property value in a string. Obtains the value of a property in this image. This API uses an asynchronous callback to return the property value in a string.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
| key | string | Yes | Name of the property. | | key | string | Yes | Name of the property. |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | Yes | Image properties, including the image index and default property value. | | options | [GetImagePropertyOptions](#getimagepropertyoptions7) | Yes | Image properties, including the image index and default property value. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the property value. If the operation fails, the default value is returned.| | callback | AsyncCallback\<string> | Yes | Callback used to return the property value. If the operation fails, the default value is returned.|
**Example** **Example**
...@@ -737,13 +1286,128 @@ imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { ...@@ -737,13 +1286,128 @@ imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {
}) })
``` ```
### modifyImageProperty<sup>9+</sup>
modifyImageProperty(key: string, value: string): Promise\<void>
Modifies the value of a property in this image. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------ |
| key | string | Yes | Name of the property.|
| value | string | Yes | New value of the property. |
**Return value**
| Type | Description |
| -------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
imageSourceApi.modifyImageProperty("ImageWidth", "120")
.then(() => {
const w = imageSourceApi.getImageProperty("ImageWidth")
console.info('w', w);
})
```
### modifyImageProperty<sup>9+</sup>
modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
Modifies the value of a property in this image. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------ |
| key | string | Yes | Name of the property. |
| value | string | Yes | New value of the property. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
```
### updateData<sup>9+</sup>
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise\<void>
Updates incremental data. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ----------- | ---- | ------------ |
| buf | ArrayBuffer | Yes | Incremental data. |
| isFinished | boolean | Yes | Whether the update is complete.|
| value | number | No | Offset for data reading. |
| length | number | No | Array length. |
**Return value**
| Type | Description |
| -------------- | -------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10).then(data => {
console.info('Succeeded in updating data.');
})
```
### updateData<sup>9+</sup>
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback\<void>): void
Updates incremental data. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------- | ---- | -------------------- |
| buf | ArrayBuffer | Yes | Incremental data. |
| isFinished | boolean | Yes | Whether the update is complete. |
| value | number | No | Offset for data reading. |
| length | number | No | Array length. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {
if(data !== undefined){
console.info('Succeeded in updating data.');
}
})
```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
createPixelMap(options?: DecodingOptions): Promise\<PixelMap> createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result. Creates a **PixelMap** object based on image decoding parameters. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -773,7 +1437,7 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void ...@@ -773,7 +1437,7 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void
Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result. Creates a **PixelMap** object based on the default parameters. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -784,11 +1448,9 @@ Creates a **PixelMap** object based on the default parameters. This API uses an ...@@ -784,11 +1448,9 @@ Creates a **PixelMap** object based on the default parameters. This API uses an
**Example** **Example**
```js ```js
imageSourceApi.createPixelMap(pixelmap => { imageSourceApi.createPixelMap((err, pixelmap) => {
console.log('Succeeded in creating pixelmap object.'); console.info('Succeeded in creating pixelmap object.');
}).catch(error => { })
console.log('Failed to create pixelmap object.');
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -797,7 +1459,7 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo ...@@ -797,7 +1459,7 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result. Creates a **PixelMap** object based on image decoding parameters. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -821,7 +1483,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -821,7 +1483,7 @@ release(callback: AsyncCallback\<void>): void
Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result. Releases this **ImageSource** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Parameters** **Parameters**
...@@ -843,13 +1505,13 @@ release(): Promise\<void> ...@@ -843,13 +1505,13 @@ release(): Promise\<void>
Releases this **ImageSource** instance. This API uses a promise to return the result. Releases this **ImageSource** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | --------------------------- |
| Promise\<void> | Promise used to return the operation result.| | Promise\<void> | Promise used to return the result.|
**Example** **Example**
...@@ -867,7 +1529,7 @@ createImagePacker(): ImagePacker ...@@ -867,7 +1529,7 @@ createImagePacker(): ImagePacker
Creates an **ImagePacker** instance. Creates an **ImagePacker** instance.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Return value** **Return value**
...@@ -887,7 +1549,7 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must ...@@ -887,7 +1549,7 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | -------------------------- | | ---------------- | -------------- | ---- | ---- | -------------------------- |
...@@ -899,7 +1561,7 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr ...@@ -899,7 +1561,7 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
Packs an image. This API uses an asynchronous callback to return the result. Packs an image. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Parameters** **Parameters**
...@@ -923,7 +1585,7 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> ...@@ -923,7 +1585,7 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
Packs an image. This API uses a promise to return the result. Packs an image. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Parameters** **Parameters**
...@@ -935,8 +1597,8 @@ Packs an image. This API uses a promise to return the result. ...@@ -935,8 +1597,8 @@ Packs an image. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------------------- | :-------------------------------------------- | | ---------------------------- | --------------------------------------------- |
| Promise\<ArrayBuffer> | Promise used to return the packed data.| | Promise\<ArrayBuffer> | Promise used to return the packed data.|
**Example** **Example**
...@@ -957,7 +1619,7 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB ...@@ -957,7 +1619,7 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB
Packs an image. This API uses an asynchronous callback to return the result. Packs an image. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Parameters** **Parameters**
...@@ -974,8 +1636,6 @@ let packOpts = { format:"image/jpeg", quality:98 } ...@@ -974,8 +1636,6 @@ let packOpts = { format:"image/jpeg", quality:98 }
const pixelMapApi = new ArrayBuffer(400); const pixelMapApi = new ArrayBuffer(400);
imagePackerApi.packing(pixelMapApi, packOpts, data => { imagePackerApi.packing(pixelMapApi, packOpts, data => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
}).catch(error => {
console.log('Failed to pack the image.');
}) })
``` ```
...@@ -985,7 +1645,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -985,7 +1645,7 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
Packs an image. This API uses a promise to return the result. Packs an image. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Parameters** **Parameters**
...@@ -996,8 +1656,8 @@ Packs an image. This API uses a promise to return the result. ...@@ -996,8 +1656,8 @@ Packs an image. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------------------- | :-------------------------------------------- | | --------------------- | -------------------------------------------- |
| Promise\<ArrayBuffer> | Promise used to return the packed data.| | Promise\<ArrayBuffer> | Promise used to return the packed data.|
**Example** **Example**
...@@ -1019,7 +1679,7 @@ release(callback: AsyncCallback\<void>): void ...@@ -1019,7 +1679,7 @@ release(callback: AsyncCallback\<void>): void
Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result. Releases this **ImagePacker** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Parameters** **Parameters**
...@@ -1041,12 +1701,12 @@ release(): Promise\<void> ...@@ -1041,12 +1701,12 @@ release(): Promise\<void>
Releases this **ImagePacker** instance. This API uses a promise to return the result. Releases this **ImagePacker** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------- | :------------------------------------------------------ | | -------------- | ------------------------------------------------------ |
| Promise\<void> | Promise used to return the instance release result. If the operation fails, an error message is returned.| | Promise\<void> | Promise used to return the instance release result. If the operation fails, an error message is returned.|
**Example** **Example**
...@@ -1098,11 +1758,11 @@ Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver ...@@ -1098,11 +1758,11 @@ Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver **System capability**: SystemCapability.Multimedia.Image.ImageReceiver
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ | | -------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup> | [Size](#size) | Yes | No | Image size. | | size | [Size](#size) | Yes | No | Image size. |
| capacity<sup>9+</sup> | number | Yes | No | Maximum number of images that can be accessed at the same time.| | capacity | number | Yes | No | Maximum number of images that can be accessed at the same time.|
| format<sup>9+</sup> | [ImageFormat](#imageformat9) | Yes | No | Image format. | | format | [ImageFormat](#imageformat9) | Yes | No | Image format. |
### getReceivingSurfaceId<sup>9+</sup> ### getReceivingSurfaceId<sup>9+</sup>
...@@ -1192,7 +1852,7 @@ Reads the latest image from the **ImageReceiver** instance. This API uses a prom ...@@ -1192,7 +1852,7 @@ Reads the latest image from the **ImageReceiver** instance. This API uses a prom
| Type | Description | | Type | Description |
| ------------------------- | ------------------ | | ------------------------- | ------------------ |
| Promise<[Image](#image8)> | Promise used to return the latest image.| | Promise<[Image](#image9)> | Promise used to return the latest image.|
**Example** **Example**
...@@ -1327,11 +1987,11 @@ Provides APIs for basic image operations, including obtaining image information ...@@ -1327,11 +1987,11 @@ Provides APIs for basic image operations, including obtaining image information
**System capability**: SystemCapability.Multimedia.Image.Core **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- | | -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect<sup>9+</sup> | [Region](#region7) | Yes | Yes | Image area to be cropped. | | clipRect | [Region](#region7) | Yes | Yes | Image area to be cropped. |
| size<sup>9+</sup> | [Size](#size) | Yes | No | Image size. | | size | [Size](#size) | Yes | No | Image size. |
| format<sup>9+</sup> | number | Yes | No | Image format. For details, see [PixelMapFormat](#pixelmapformat7).| | format | number | Yes | No | Image format. For details, see [PixelMapFormat](#pixelmapformat7).|
### getComponent<sup>9+</sup> ### getComponent<sup>9+</sup>
...@@ -1407,8 +2067,6 @@ The corresponding resources must be released before another image arrives. ...@@ -1407,8 +2067,6 @@ The corresponding resources must be released before another image arrives.
```js ```js
img.release(() =>{ img.release(() =>{
console.log('release succeeded.'); console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
}) })
``` ```
...@@ -1442,7 +2100,7 @@ img.release().then(() =>{ ...@@ -1442,7 +2100,7 @@ img.release().then(() =>{
Describes area information in an image. Describes area information in an image.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
...@@ -1455,7 +2113,7 @@ Describes area information in an image. ...@@ -1455,7 +2113,7 @@ Describes area information in an image.
Describes image information. Describes image information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name| Type | Readable| Writable| Description | | Name| Type | Readable| Writable| Description |
| ---- | ------------- | ---- | ---- | ---------- | | ---- | ------------- | ---- | ---- | ---------- |
...@@ -1465,7 +2123,7 @@ Describes image information. ...@@ -1465,7 +2123,7 @@ Describes image information.
Describes the size of an image. Describes the size of an image.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | -------------- | | ------ | ------ | ---- | ---- | -------------- |
...@@ -1476,19 +2134,20 @@ Describes the size of an image. ...@@ -1476,19 +2134,20 @@ Describes the size of an image.
Enumerates the pixel formats of images. Enumerates the pixel formats of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| --------- | ------ | ----------------- | | ---------------------- | ------ | ----------------- |
| UNKNOWN | 0 | Unknown format. | | UNKNOWN | 0 | Unknown format. |
| RGBA_8888 | 3 | RGBA_8888.| | RGB_565 | 2 | RGB_565. |
| RGB_565 | 2 | RGB_565. | | RGBA_8888 | 3 | RGBA_8888.|
| BGRA_8888<sup>9+</sup> | 4 | BGRA_8888.|
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
Enumerates the alpha types of images. Enumerates the alpha types of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| -------- | ------ | ----------------------- | | -------- | ------ | ----------------------- |
...@@ -1501,32 +2160,45 @@ Enumerates the alpha types of images. ...@@ -1501,32 +2160,45 @@ Enumerates the alpha types of images.
Enumerates the scale modes of images. Enumerates the scale modes of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| --------------- | ------ | -------------------------------------------------- | | --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.| | CENTER_CROP | 1 | Scales the image so that it fills the requested bounds of the target and crops the extra.|
| FIT_TARGET_SIZE | 2 | Reduces the image size to the dimensions of the target. | | FIT_TARGET_SIZE | 2 | Reduces the image size to the dimensions of the target. |
## SourceOptions<sup>9+</sup>
Defines image source initialization options.
**System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description |
| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
| sourceDensity | number | Yes | Yes | Density of the image source.|
| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel format of the image source. |
| sourceSize | [Size](#size) | Yes | Yes | Pixel size of the image source. |
## InitializationOptions<sup>8+</sup> ## InitializationOptions<sup>8+</sup>
Defines pixel map initialization options. Defines pixel map initialization options.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------------- | ---------------------------------- | ---- | ---- | -------------- | | ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. | | alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. |
| editable | boolean | Yes | Yes | Whether the image is editable. | | editable | boolean | Yes | Yes | Whether the image is editable. |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. | | scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | Yes | Yes | Scale mode. |
| size | [Size](#size) | Yes | Yes | Image size.| | size | [Size](#size) | Yes | Yes | Image size.|
## DecodingOptions<sup>7+</sup> ## DecodingOptions<sup>7+</sup>
Defines image decoding options. Defines image decoding options.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | | ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
...@@ -1542,7 +2214,7 @@ Defines image decoding options. ...@@ -1542,7 +2214,7 @@ Defines image decoding options.
Describes region information. Describes region information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name| Type | Readable| Writable| Description | | Name| Type | Readable| Writable| Description |
| ---- | ------------- | ---- | ---- | ------------ | | ---- | ------------- | ---- | ---- | ------------ |
...@@ -1554,18 +2226,18 @@ Describes region information. ...@@ -1554,18 +2226,18 @@ Describes region information.
Defines the option for image packing. Defines the option for image packing.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImagePacker
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------- | ------ | ---- | ---- | -------------- | | ------- | ------ | ---- | ---- | --------------------------------------------------- |
| format | string | Yes | Yes | Format of the packed image. | | format | string | Yes | Yes | Format of the packed image. |
| quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.| | quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.|
## GetImagePropertyOptions<sup>7+</sup> ## GetImagePropertyOptions<sup>7+</sup>
Describes image properties. Describes image properties.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.ImageSource
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------ | ------ | ---- | ---- | ------------ | | ------------ | ------ | ---- | ---- | ------------ |
...@@ -1576,18 +2248,18 @@ Describes image properties. ...@@ -1576,18 +2248,18 @@ Describes image properties.
Describes the exchangeable image file format (Exif) information of an image. Describes the exchangeable image file format (Exif) information of an image.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image.Core
| Name | Default Value | Description | | Name | Default Value | Description |
| ----------------- | ----------------- | -------------------- | | ----------------- | ----------------------- | ------------------------ |
| BITS_PER_SAMPLE | "BitsPerSample" | Number of bits per pixel. | | BITS_PER_SAMPLE | "BitsPerSample" | Number of bits per pixel. |
| ORIENTATION | "Orientation" | Image orientation. | | ORIENTATION | "Orientation" | Image orientation. |
| IMAGE_LENGTH | "ImageLength" | Image length. | | IMAGE_LENGTH | "ImageLength" | Image length. |
| IMAGE_WIDTH | "ImageWidth" | Image width. | | IMAGE_WIDTH | "ImageWidth" | Image width. |
| GPS_LATITUDE | "GPSLatitude" | Image latitude. | | GPS_LATITUDE | "GPSLatitude" | Image latitude. |
| GPS_LONGITUDE | "GPSLongitude" | Image longitude. | | GPS_LONGITUDE | "GPSLongitude" | Image longitude. |
| GPS_LATITUDE_REF | "GPSLatitudeRef" | Latitude reference, for example, N or S.| | GPS_LATITUDE_REF | "GPSLatitudeRef" | Latitude reference, for example, N or S. |
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E.| | GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E. |
## ImageFormat<sup>9+</sup> ## ImageFormat<sup>9+</sup>
...@@ -1625,3 +2297,45 @@ Describes the color components of an image. ...@@ -1625,3 +2297,45 @@ Describes the color components of an image.
| rowStride | number | Yes | No | Row stride. | | rowStride | number | Yes | No | Row stride. |
| pixelStride | number | Yes | No | Pixel stride. | | pixelStride | number | Yes | No | Pixel stride. |
| byteBuffer | ArrayBuffer | Yes | No | Component buffer.| | byteBuffer | ArrayBuffer | Yes | No | Component buffer.|
## ResponseCode
Enumerates the response codes returned upon build errors.
| Name | Value | Description |
| ----------------------------------- | -------- | --------------------------------------------------- |
| ERR_MEDIA_INVALID_VALUE | -1 | Invalid value. |
| SUCCESS | 0 | Operation successful. |
| ERROR | 62980096 | Operation failed. |
| ERR_IPC | 62980097 | IPC error. |
| ERR_SHAMEM_NOT_EXIST | 62980098 | The shared memory does not exist. |
| ERR_SHAMEM_DATA_ABNORMAL | 62980099 | The shared memory is abnormal. |
| ERR_IMAGE_DECODE_ABNORMAL | 62980100 | An error occurs during image decoding. |
| ERR_IMAGE_DATA_ABNORMAL | 62980101 | The input image data is incorrect. |
| ERR_IMAGE_MALLOC_ABNORMAL | 62980102 | An error occurs during image memory allocation. |
| ERR_IMAGE_DATA_UNSUPPORT | 62980103 | Unsupported image type. |
| ERR_IMAGE_INIT_ABNORMAL | 62980104 | An error occurs during image initialization. |
| ERR_IMAGE_GET_DATA_ABNORMAL | 62980105 | An error occurs during image data retrieval. |
| ERR_IMAGE_TOO_LARGE | 62980106 | The image data is too large. |
| ERR_IMAGE_TRANSFORM | 62980107 | An error occurs during image transformation. |
| ERR_IMAGE_COLOR_CONVERT | 62980108 | An error occurs during image color conversion. |
| ERR_IMAGE_CROP | 62980109 | An error occurs during image cropping. |
| ERR_IMAGE_SOURCE_DATA | 62980110 | The image source data is incorrect. |
| ERR_IMAGE_SOURCE_DATA_INCOMPLETE | 62980111 | The image source data is incomplete. |
| ERR_IMAGE_MISMATCHED_FORMAT | 62980112 | The image format does not match. |
| ERR_IMAGE_UNKNOWN_FORMAT | 62980113 | Unknown image format. |
| ERR_IMAGE_SOURCE_UNRESOLVED | 62980114 | The image source is not parsed. |
| ERR_IMAGE_INVALID_PARAMETER | 62980115 | Invalid image parameter. |
| ERR_IMAGE_DECODE_FAILED | 62980116 | Decoding failed. |
| ERR_IMAGE_PLUGIN_REGISTER_FAILED | 62980117 | Failed to register the plug-in. |
| ERR_IMAGE_PLUGIN_CREATE_FAILED | 62980118 | Failed to create the plug-in. |
| ERR_IMAGE_ENCODE_FAILED | 62980119 | Failed to encode the image. |
| ERR_IMAGE_ADD_PIXEL_MAP_FAILED | 62980120 | Failed to add the image pixel map. |
| ERR_IMAGE_HW_DECODE_UNSUPPORT | 62980121 | Unsupported image hardware decoding. |
| ERR_IMAGE_DECODE_HEAD_ABNORMAL | 62980122 | The image decoding header is incorrect. |
| ERR_IMAGE_DECODE_EXIF_UNSUPPORT | 62980123 | EXIF decoding is not supported. |
| ERR_IMAGE_PROPERTY_NOT_EXIST | 62980124 | The image property does not exist. The error codes for the image start from 150.|
| ERR_IMAGE_READ_PIXELMAP_FAILED | 62980246 | Failed to read the pixel map. |
| ERR_IMAGE_WRITE_PIXELMAP_FAILED | 62980247 | Failed to write the pixel map. |
| ERR_IMAGE_PIXELMAP_NOT_ALLOW_MODIFY | 62980248 | Modification to the pixel map is not allowed. |
| ERR_IMAGE_CONFIG_FAILED | 62980259 | The software parameter setting is incorrect. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册