未验证 提交 f322ef63 编写于 作者: O openharmony_ci 提交者: Gitee

!10178 翻译完成:10055+10067 image文档整改

Merge pull request !10178 from wusongqing/TR10055
...@@ -115,7 +115,7 @@ const readBuffer = new ArrayBuffer(96); ...@@ -115,7 +115,7 @@ 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 => {
('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) ...@@ -261,12 +261,7 @@ image.createPixelMap(color, opts)
} }
pixelmap.writePixels(area).then(() => { pixelmap.writePixels(area).then(() => {
const readArea = { pixels: new ArrayBuffer(8), console.info('Succeeded to write pixelmap into the specified area.');
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 }
}
}) })
}).catch(error => { }).catch(error => {
console.log('error: ' + error); console.log('error: ' + error);
...@@ -291,17 +286,20 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t ...@@ -291,17 +286,20 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t
**Example** **Example**
```js ```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) => { 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 = { console.info('Succeeded to write pixelmap into the specified area.');
pixels: new ArrayBuffer(20),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
} }
}) })
``` ```
...@@ -330,9 +328,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj ...@@ -330,9 +328,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color); 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."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((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.");
...@@ -358,9 +358,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj ...@@ -358,9 +358,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color); 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) { if (err) {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
return; return;
...@@ -387,12 +389,22 @@ Obtains pixel map information of this image. This API uses a promise to return t ...@@ -387,12 +389,22 @@ Obtains pixel map information of this image. This API uses a promise to return t
**Example** **Example**
```js ```js
const pixelMap = new ArrayBuffer(400); const color = new ArrayBuffer(96);
pixelMap.getImageInfo().then(function(info) { let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
console.log("Succeeded in obtaining the image pixel map information."); image.createPixelMap(color, opts).then(pixelmap => {
}).catch((err) => { globalpixelmap = pixelmap;
console.error("Failed to obtain the image pixel map information."); 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.");
}
})
})
``` ```
### getImageInfo<sup>7+</sup> ### getImageInfo<sup>7+</sup>
...@@ -412,8 +424,21 @@ Obtains pixel map information of this image. This API uses an asynchronous callb ...@@ -412,8 +424,21 @@ Obtains pixel map information of this image. This API uses an asynchronous callb
**Example** **Example**
```js ```js
pixelmap.getImageInfo((imageInfo) => { const color = new ArrayBuffer(96);
console.log("Succeeded in obtaining the image pixel map information."); 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 ...@@ -500,9 +525,15 @@ Sets an opacity rate for this image pixel map. This API uses an asynchronous cal
**Example** **Example**
```js ```js
async function () { var rate = 0.5;
await pixelMap.opacity(0.5); pixelmap.opacity(rate, (err) => {
} if (err) {
console.error("Failed to set opacity.");
return;
} else {
console.log("Succeeded in setting opacity.");
}
})
``` ```
### opacity<sup>9+</sup> ### opacity<sup>9+</sup>
...@@ -529,7 +560,8 @@ Sets an opacity rate for this image pixel map. This API uses a promise to return ...@@ -529,7 +560,8 @@ Sets an opacity rate for this image pixel map. This API uses a promise to return
```js ```js
async function () { 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. ...@@ -550,12 +582,8 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**Example** **Example**
```js ```js
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => { async function () {
if (alphaPixelMap == undefined) { await pixelmap.createAlphaPixelmap();
console.info('Failed to obtain new pixel map.');
} else {
console.info('Succeed in obtaining new pixel map.');
}
}) })
``` ```
...@@ -576,14 +604,13 @@ Creates a **PixelMap** object that contains only the alpha channel information. ...@@ -576,14 +604,13 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**Example** **Example**
```js ```js
let pixelMap = await imageSource.createPixelMap(); pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
if (pixelMap != undefined) { if (alphaPixelMap == undefined) {
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => { console.info('Failed to obtain new pixel map.');
console.info('Failed to obtain new pixel map.'); } else {
}) console.info('Succeed in obtaining new pixel map.');
} else { }
console.info('Succeed in obtaining new pixel map.'); })
}
``` ```
### scale<sup>9+</sup> ### scale<sup>9+</sup>
...@@ -606,7 +633,7 @@ Scales this image based on the input width and height. This API uses an asynchro ...@@ -606,7 +633,7 @@ Scales this image based on the input width and height. This API uses an asynchro
```js ```js
async function () { 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 ...@@ -635,7 +662,7 @@ Scales this image based on the input width and height. This API uses a promise t
```js ```js
async function () { 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 ...@@ -659,7 +686,7 @@ Translates this image based on the input coordinates. This API uses an asynchron
```js ```js
async function () { 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 ...@@ -688,7 +715,7 @@ Translates this image based on the input coordinates. This API uses a promise to
```js ```js
async function () { 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 ...@@ -711,7 +738,7 @@ Rotates this image based on the input angle. This API uses an asynchronous callb
```js ```js
async function () { 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 ...@@ -739,7 +766,7 @@ Rotates this image based on the input angle. This API uses a promise to return t
```js ```js
async function () { 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 ...@@ -763,7 +790,7 @@ Flips this image horizontally or vertically, or both. This API uses an asynchron
```js ```js
async function () { 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 ...@@ -792,7 +819,7 @@ Flips this image horizontally or vertically, or both. This API uses a promise to
```js ```js
async function () { 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 ...@@ -815,7 +842,7 @@ Crops this image based on the input size. This API uses an asynchronous callback
```js ```js
async function () { 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 ...@@ -843,7 +870,7 @@ Crops this image based on the input size. This API uses a promise to return the
```js ```js
async function () { 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. ...@@ -954,7 +981,8 @@ Creates an **ImageSource** instance based on the URI.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource('/sdcard/test.jpg'); var sourceOptions = { sourceDensity: 120 };
let imageSource = image.createImageSource('test.png', sourceOptions);
``` ```
## image.createImageSource<sup>7+</sup> ## image.createImageSource<sup>7+</sup>
...@@ -1007,7 +1035,8 @@ Creates an **ImageSource** instance based on the file descriptor. ...@@ -1007,7 +1035,8 @@ Creates an **ImageSource** instance based on the file descriptor.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource(fd); var sourceOptions = { sourceDensity: 120 };
const imageSourceApi = image.createImageSource(0, sourceOptions);
``` ```
## image.createImageSource<sup>9+</sup> ## image.createImageSource<sup>9+</sup>
...@@ -1059,9 +1088,9 @@ const data = new ArrayBuffer(112); ...@@ -1059,9 +1088,9 @@ const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data); const imageSourceApi = image.createImageSource(data);
``` ```
## image.CreateIncrementalSource<sup>9+</sup> ## image.createIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer): ImageSource createIncrementalSource(buf: ArrayBuffer): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers. 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. ...@@ -1083,12 +1112,12 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js ```js
const buf = new ArrayBuffer(96); const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
``` ```
## image.CreateIncrementalSource<sup>9+</sup> ## image.createIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource createIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers. 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. ...@@ -1111,7 +1140,7 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js ```js
const buf = new ArrayBuffer(96); const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
``` ```
## ImageSource ## ImageSource
...@@ -1124,7 +1153,7 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour ...@@ -1124,7 +1153,7 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.| | supportedFormats | Array\<string> | Yes | No | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and RAW.|
### getImageInfo ### getImageInfo
...@@ -1282,7 +1311,7 @@ Obtains the value of a property in this image. This API uses an asynchronous cal ...@@ -1282,7 +1311,7 @@ Obtains the value of a property in this image. This API uses an asynchronous cal
**Example** **Example**
```js ```js
const property = new ArrayBuffer(400); let property = { index: 0, defaultValue: '9999' }
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {
if(error) { if(error) {
console.log('Failed to get the value of the specified attribute key of the image.'); console.log('Failed to get the value of the specified attribute key of the image.');
...@@ -1477,7 +1506,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses ...@@ -1477,7 +1506,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses
**Example** **Example**
```js ```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 => { imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('Succeeded in creating pixelmap object.'); console.log('Succeeded in creating pixelmap object.');
}) })
...@@ -1551,7 +1588,7 @@ const imagePackerApi = image.createImagePacker(); ...@@ -1551,7 +1588,7 @@ const imagePackerApi = image.createImagePacker();
## ImagePacker ## 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 ### Attributes
...@@ -1581,7 +1618,6 @@ Packs an image. This API uses an asynchronous callback to return the result. ...@@ -1581,7 +1618,6 @@ Packs an image. This API uses an asynchronous callback to return the result.
```js ```js
let packOpts = { format:"image/jpeg", quality:98 }; let packOpts = { format:"image/jpeg", quality:98 };
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts, data => {}) imagePackerApi.packing(imageSourceApi, packOpts, data => {})
``` ```
...@@ -1610,7 +1646,6 @@ Packs an image. This API uses a promise to return the result. ...@@ -1610,7 +1646,6 @@ Packs an image. This API uses a promise to return the result.
```js ```js
let packOpts = { format:"image/jpeg", quality:98 } let packOpts = { format:"image/jpeg", quality:98 }
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { .then( data => {
console.log('packing succeeded.'); console.log('packing succeeded.');
...@@ -2112,7 +2147,7 @@ Describes area information in an image. ...@@ -2112,7 +2147,7 @@ Describes area information in an image.
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer | Yes | No | Pixels of the image. | | pixels | ArrayBuffer | Yes | No | Pixels of the image. |
| offset | number | Yes | No | Offset for data reading. | | 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.| | 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 ## ImageInfo
...@@ -2146,8 +2181,8 @@ Enumerates the pixel formats of images. ...@@ -2146,8 +2181,8 @@ Enumerates the pixel formats of images.
| ---------------------- | ------ | ----------------- | | ---------------------- | ------ | ----------------- |
| UNKNOWN | 0 | Unknown format. | | UNKNOWN | 0 | Unknown format. |
| RGB_565 | 2 | RGB_565. | | RGB_565 | 2 | RGB_565. |
| RGBA_8888 | 3 | RGBA_8888.| | RGBA_8888 | 3 | RGBA_8888. |
| BGRA_8888<sup>9+</sup> | 4 | BGRA_8888.| | BGRA_8888<sup>9+</sup> | 4 | BGRA_8888. |
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
...@@ -2159,8 +2194,8 @@ Enumerates the alpha types of images. ...@@ -2159,8 +2194,8 @@ Enumerates the alpha types of images.
| -------- | ------ | ----------------------- | | -------- | ------ | ----------------------- |
| UNKNOWN | 0 | Unknown alpha type. | | UNKNOWN | 0 | Unknown alpha type. |
| OPAQUE | 1 | There is no alpha or the image is opaque.| | OPAQUE | 1 | There is no alpha or the image is opaque.|
| PREMUL | 2 | Premultiplied alpha. | | PREMUL | 2 | Premultiplied alpha. |
| UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. | | UNPREMUL | 3 | Unpremultiplied alpha, that is, straight alpha. |
## ScaleMode<sup>9+</sup> ## ScaleMode<sup>9+</sup>
...@@ -2236,7 +2271,7 @@ Defines the option for image packing. ...@@ -2236,7 +2271,7 @@ Defines the option for image packing.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------- | ------ | ---- | ---- | --------------------------------------------------- | | ------- | ------ | ---- | ---- | --------------------------------------------------- |
| format | string | Yes | Yes | Format of the packed image.<br>Currently, the following raw formats are supported: .jpg, .png, .gif, .bmp, and .webp. | | format | string | Yes | Yes | Format of the packed image.<br>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.| | 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>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册