diff --git a/en/application-dev/reference/apis/js-apis-image.md b/en/application-dev/reference/apis/js-apis-image.md
index bcbf619bf7173a405eee37f5dac86c5e87a023e9..866a5833b69feb01da451f2464fbdd7915f06172 100644
--- a/en/application-dev/reference/apis/js-apis-image.md
+++ b/en/application-dev/reference/apis/js-apis-image.md
@@ -115,7 +115,7 @@ const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
}).catch(error => {
- ('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.
})
```
@@ -261,12 +261,7 @@ image.createPixelMap(color, opts)
}
pixelmap.writePixels(area).then(() => {
- const readArea = { pixels: new ArrayBuffer(8),
- offset: 0,
- stride: 8,
- // region.size.width + x < opts.width, region.size.height + y < opts.height
- region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
- }
+ console.info('Succeeded to write pixelmap into the specified area.');
})
}).catch(error => {
console.log('error: ' + error);
@@ -291,17 +286,20 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t
**Example**
```js
-const area = new ArrayBuffer(400);
+const area = { pixels: new ArrayBuffer(8),
+ offset: 0,
+ stride: 8,
+ region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
+}
+let bufferArr = new Uint8Array(area.pixels);
+for (var i = 0; i < bufferArr.length; i++) {
+ bufferArr[i] = i + 1;
+}
pixelmap.writePixels(area, (error) => {
if (error != undefined) {
console.info('Failed to write pixelmap into the specified area.');
} else {
- const readArea = {
- pixels: new ArrayBuffer(20),
- offset: 0,
- stride: 8,
- region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
- }
+ console.info('Succeeded to write pixelmap into the specified area.');
}
})
```
@@ -330,9 +328,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js
const color = new ArrayBuffer(96);
-const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color);
-pixelMap.writeBufferToPixels(color).then(() => {
+for (var i = 0; i < bufferArr.length; i++) {
+ bufferArr[i] = i + 1;
+}
+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.");
@@ -358,9 +358,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js
const color = new ArrayBuffer(96);
-const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color);
-pixelMap.writeBufferToPixels(color, function(err) {
+for (var i = 0; i < bufferArr.length; i++) {
+ bufferArr[i] = i + 1;
+}
+pixelmap.writeBufferToPixels(color, function(err) {
if (err) {
console.error("Failed to write data from a buffer to a PixelMap.");
return;
@@ -387,12 +389,22 @@ Obtains pixel map information of this image. This API uses a promise to return t
**Example**
```js
-const pixelMap = new ArrayBuffer(400);
-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.");
-});
+const color = new ArrayBuffer(96);
+let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
+image.createPixelMap(color, opts).then(pixelmap => {
+ globalpixelmap = pixelmap;
+ if (pixelmap == undefined) {
+ console.error("Failed to obtain the image pixel map information.");
+ }
+ pixelmap.getImageInfo().then(imageInfo => {
+ if (imageInfo == undefined) {
+ console.error("Failed to obtain the image pixel map information.");
+ }
+ if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
+ console.log("Succeeded in obtaining the image pixel map information.");
+ }
+ })
+})
```
### getImageInfo7+
@@ -412,8 +424,21 @@ Obtains pixel map information of this image. This API uses an asynchronous callb
**Example**
```js
-pixelmap.getImageInfo((imageInfo) => {
- console.log("Succeeded in obtaining the image pixel map information.");
+const color = new ArrayBuffer(96);
+let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
+image.createPixelMap(color, opts, (err, pixelmap) => {
+ if (pixelmap == undefined) {
+ globalpixelmap = pixelmap;
+ console.error("Failed to obtain the image pixel map information.");
+ }
+ pixelmap.getImageInfo((err, imageInfo) => {
+ if (imageInfo == undefined) {
+ console.error("Failed to obtain the image pixel map information.");
+ }
+ if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
+ console.log("Succeeded in obtaining the image pixel map information.");
+ }
+ })
})
```
@@ -500,9 +525,15 @@ Sets an opacity rate for this image pixel map. This API uses an asynchronous cal
**Example**
```js
-async function () {
- await pixelMap.opacity(0.5);
-}
+var rate = 0.5;
+pixelmap.opacity(rate, (err) => {
+ if (err) {
+ console.error("Failed to set opacity.");
+ return;
+ } else {
+ console.log("Succeeded in setting opacity.");
+ }
+})
```
### opacity9+
@@ -529,7 +560,8 @@ Sets an opacity rate for this image pixel map. This API uses a promise to return
```js
async function () {
- await pixelMap.opacity(0.5);
+ var rate = 0.5;
+ await pixelmap.opacity(rate);
}
```
@@ -550,12 +582,8 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**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.');
- }
+async function () {
+ await pixelmap.createAlphaPixelmap();
})
```
@@ -576,14 +604,13 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**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.');
-}
+pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
+ if (alphaPixelMap == undefined) {
+ console.info('Failed to obtain new pixel map.');
+ } else {
+ console.info('Succeed in obtaining new pixel map.');
+ }
+})
```
### scale9+
@@ -606,7 +633,7 @@ Scales this image based on the input width and height. This API uses an asynchro
```js
async function () {
- await pixelMap.scale(2.0, 1.0);
+ await pixelmap.scale(2.0, 1.0);
}
```
@@ -635,7 +662,7 @@ Scales this image based on the input width and height. This API uses a promise t
```js
async function () {
- await pixelMap.scale(2.0, 1.0);
+ await pixelmap.scale(2.0, 1.0);
}
```
@@ -659,7 +686,7 @@ Translates this image based on the input coordinates. This API uses an asynchron
```js
async function () {
- await pixelMap.translate(3.0, 1.0);
+ await pixelmap.translate(3.0, 1.0);
}
```
@@ -688,7 +715,7 @@ Translates this image based on the input coordinates. This API uses a promise to
```js
async function () {
- await pixelMap.translate(3.0, 1.0);
+ await pixelmap.translate(3.0, 1.0);
}
```
@@ -711,7 +738,7 @@ Rotates this image based on the input angle. This API uses an asynchronous callb
```js
async function () {
- await pixelMap.rotate(90.0);
+ await pixelmap.rotate(90.0);
}
```
@@ -739,7 +766,7 @@ Rotates this image based on the input angle. This API uses a promise to return t
```js
async function () {
- await pixelMap.rotate(90.0);
+ await pixelmap.rotate(90.0);
}
```
@@ -763,7 +790,7 @@ Flips this image horizontally or vertically, or both. This API uses an asynchron
```js
async function () {
- await pixelMap.flip(false, true);
+ await pixelmap.flip(false, true);
}
```
@@ -792,7 +819,7 @@ Flips this image horizontally or vertically, or both. This API uses a promise to
```js
async function () {
- await pixelMap.flip(false, true);
+ await pixelmap.flip(false, true);
}
```
@@ -815,7 +842,7 @@ Crops this image based on the input size. This API uses an asynchronous callback
```js
async function () {
- await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
+ await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
}
```
@@ -843,7 +870,7 @@ Crops this image based on the input size. This API uses a promise to return the
```js
async function () {
- await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
+ await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
}
```
@@ -954,7 +981,8 @@ Creates an **ImageSource** instance based on the URI.
**Example**
```js
-const imageSourceApi = image.createImageSource('/sdcard/test.jpg');
+var sourceOptions = { sourceDensity: 120 };
+let imageSource = image.createImageSource('test.png', sourceOptions);
```
## image.createImageSource7+
@@ -1007,7 +1035,8 @@ Creates an **ImageSource** instance based on the file descriptor.
**Example**
```js
-const imageSourceApi = image.createImageSource(fd);
+var sourceOptions = { sourceDensity: 120 };
+const imageSourceApi = image.createImageSource(0, sourceOptions);
```
## image.createImageSource9+
@@ -1059,9 +1088,9 @@ const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);
```
-## image.CreateIncrementalSource9+
+## image.createIncrementalSource9+
-CreateIncrementalSource(buf: ArrayBuffer): ImageSource
+createIncrementalSource(buf: ArrayBuffer): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers.
@@ -1083,12 +1112,12 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js
const buf = new ArrayBuffer(96);
-const imageSourceApi = image.CreateIncrementalSource(buf);
+const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
```
-## image.CreateIncrementalSource9+
+## image.createIncrementalSource9+
-CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
+createIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers.
@@ -1111,7 +1140,7 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js
const buf = new ArrayBuffer(96);
-const imageSourceApi = image.CreateIncrementalSource(buf);
+const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
```
## ImageSource
@@ -1124,7 +1153,7 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour
| Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
-| supportedFormats | Array\ | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.|
+| supportedFormats | Array\ | Yes | No | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and RAW.|
### getImageInfo
@@ -1282,7 +1311,7 @@ Obtains the value of a property in this image. This API uses an asynchronous cal
**Example**
```js
-const property = new ArrayBuffer(400);
+let property = { index: 0, defaultValue: '9999' }
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {
if(error) {
console.log('Failed to get the value of the specified attribute key of the image.');
@@ -1477,7 +1506,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses
**Example**
```js
-const decodingOptions = new ArrayBuffer(400);
+let decodingOptions = {
+ sampleSize: 1,
+ editable: true,
+ desiredSize: { width: 1, height: 2 },
+ rotate: 10,
+ desiredPixelFormat: 3,
+ desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
+ index: 0
+};
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('Succeeded in creating pixelmap object.');
})
@@ -1551,7 +1588,7 @@ const imagePackerApi = image.createImagePacker();
## ImagePacker
-Provide APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance.
+Provides APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance. The image formats JPEG and WebP are supported.
### Attributes
@@ -1581,7 +1618,6 @@ Packs an image. This API uses an asynchronous callback to return the result.
```js
let packOpts = { format:"image/jpeg", quality:98 };
-const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
```
@@ -1610,7 +1646,6 @@ Packs an image. This API uses a promise to return the result.
```js
let packOpts = { format:"image/jpeg", quality:98 }
-const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => {
console.log('packing succeeded.');
@@ -2112,7 +2147,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
@@ -2146,8 +2181,8 @@ Enumerates the pixel formats of images.
| ---------------------- | ------ | ----------------- |
| UNKNOWN | 0 | Unknown format. |
| RGB_565 | 2 | RGB_565. |
-| RGBA_8888 | 3 | RGBA_8888.|
-| BGRA_88889+ | 4 | BGRA_8888.|
+| RGBA_8888 | 3 | RGBA_8888. |
+| BGRA_88889+ | 4 | BGRA_8888. |
## AlphaType9+
@@ -2159,8 +2194,8 @@ Enumerates the alpha types of images.
| -------- | ------ | ----------------------- |
| UNKNOWN | 0 | Unknown alpha type. |
| OPAQUE | 1 | There is no alpha or the image is opaque.|
-| PREMUL | 2 | Premultiplied alpha. |
-| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. |
+| PREMUL | 2 | Premultiplied alpha. |
+| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. |
## ScaleMode9+
@@ -2236,7 +2271,7 @@ Defines the option for image packing.
| Name | Type | Readable| Writable| Description |
| ------- | ------ | ---- | ---- | --------------------------------------------------- |
-| format | string | Yes | Yes | Format of the packed image.
Currently, the following raw formats are supported: .jpg, .png, .gif, .bmp, and .webp. |
+| format | string | Yes | Yes | Format of the packed image.
Currently, the JPEG and WebP formats are supported. |
| quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.|
## GetImagePropertyOptions7+