提交 567053a4 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 5792198c
Image Processing # Image Processing
==========
> **NOTE** > **NOTE**
> The initial APIs of this module are supported since API version 8. 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 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import ## Modules to Import
---------
``` ```
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
createPixelMap(colors: ArrayBuffer, opts: InitializetionOptions): Promise\<PixelMap> createPixelMap(colors: ArrayBuffer, options: InitializetionOptions): 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.
...@@ -20,30 +18,28 @@ Creates a **PixelMap** object. This API uses a promise to return the result. ...@@ -20,30 +18,28 @@ Creates a **PixelMap** object. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors | ArrayBuffer | Yes | Color array. | | colors | ArrayBuffer | Yes | Color array. |
| opts | [InitializetionOptions](#InitializationOptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| | options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------------- | -------------- | | -------------------------------- | -------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object created.| | Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
**Example** **Example**
```js ```js
image.createPixelMap(Color, opts) image.createPixelMap(Color, opts)
.then((pixelmap) => { .then((pixelmap) => {
expect(pixelmap !== null).assertTrue()
done()
}) })
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
createPixelMap(colors: ArrayBuffer, opts: InitializetionOptions) callback: AsyncCallback\<PixelMap>): void createPixelMap(colors: ArrayBuffer, options: InitializetionOptions, callback: AsyncCallback\<PixelMap>): void
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.
...@@ -51,18 +47,16 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return ...@@ -51,18 +47,16 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors | ArrayBuffer | Yes | Color array. | | colors | ArrayBuffer | Yes | Color array. |
| opts | [InitializetionOptions](#InitializationOptions8) | Yes | Pixel properties. | | options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties. |
| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object obtained.| | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.|
**Example** **Example**
```js ```js
image.createPixelMap(Color, opts, (pixelmap) => { image.createPixelMap(Color, opts, (pixelmap) => {
expect(pixelmap !== null).assertTrue()
done()
}) })
``` ```
...@@ -100,25 +94,10 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u ...@@ -100,25 +94,10 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u
```js ```js
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(readBuffer).then(() => {
var bufferArr = new Uint8Array(readBuffer) // Called if the condition is met.
var res = true }).catch(error => {
for (var i = 0; i < bufferArr.length; i++) { // Called if no condition is met.
if (res) { })
if (bufferArr[i] !== 0) {
res = false
console.info('TC_020 Success')
expect(true).assertTrue()
done()
break
}
}
}
if (res) {
console.info('TC_020 buffer is all empty')
expect(false).assertTrue()
done()
}
})
``` ```
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -140,24 +119,6 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u ...@@ -140,24 +119,6 @@ Reads image pixel map data and writes the data to an **ArrayBuffer**. This API u
```js ```js
pixelmap.readPixelsToBuffer(readBuffer, () => { pixelmap.readPixelsToBuffer(readBuffer, () => {
var bufferArr = new Uint8Array(readBuffer)
var res = true
for (var i = 0; i < bufferArr.length; i++) {
if (res) {
if (bufferArr[i] !== 0) {
res = false
console.info('TC_020-1 Success')
expect(true).assertTrue()
done()
break
}
}
}
if (res) {
console.info('TC_020-1 buffer is all empty')
expect(false).assertTrue()
done()
}
}) })
``` ```
...@@ -185,28 +146,10 @@ Reads pixel map data in an area. This API uses a promise to return the data read ...@@ -185,28 +146,10 @@ Reads pixel map data in an area. This API uses a promise to return the data read
```js ```js
pixelmap.readPixels(area).then((data) => { pixelmap.readPixels(area).then((data) => {
if(data !== null){ // Called if the condition is met.
var bufferArr = new Uint8Array(area.pixels); }).catch(error => {
var res = true; // Called if no condition is met.
for (var i = 0; i < bufferArr.length; i++) { })
console.info('TC_021 buffer ' + bufferArr[i]);
if(res) {
if (bufferArr[i] == 0) {
res = false;
console.info('TC_021 Success');
expect(true).assertTrue();
done();
break;
}
}
}
if (res) {
console.info('TC_021 buffer is all empty');
expect(false).assertTrue()
done();
}
}
})
``` ```
### readPixels<sup>7+</sup> ### readPixels<sup>7+</sup>
...@@ -227,22 +170,22 @@ Reads image pixel map data in an area. This API uses a callback to return the da ...@@ -227,22 +170,22 @@ Reads image pixel map data in an area. This API uses a callback to return the da
**Example** **Example**
```js ```js
pixelmap.readPixels(area,(data) => { let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
if(data !== null) { image.createPixelMap(color, opts, (err, pixelmap) => {
var bufferArr = new Uint8Array(area.pixels); if(pixelmap == undefined){
var res = true; console.info('createPixelMap failed');
for (var i = 0; i < bufferArr.length; i++) { expect(false).assertTrue();
console.info('TC_021-1 buffer ' + bufferArr[i]); done();
if(res) { }else{
if(bufferArr[i] == 0) { const area = { pixels: new ArrayBuffer(8),
res = false; offset: 0,
console.info('TC_021-1 Success'); stride: 8,
expect(true).assertTrue(); region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}
done(); pixelmap.readPixels(area, () => {
break; console.info('readPixels success');
} })
} }
} })
``` ```
### writePixels<sup>7+</sup> ### writePixels<sup>7+</sup>
...@@ -257,7 +200,7 @@ Writes image pixel map data to an area. This API uses a promise to return the op ...@@ -257,7 +200,7 @@ Writes image pixel map data to an area. This API uses a promise to return the op
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | -------------------- | | ------ | ------------------------------ | ---- | -------------------- |
| area | [PositionArea](#PositionArea7) | Yes | Area to which the pixel map data will be written.| | area | [PositionArea](#positionarea7) | Yes | Area to which the pixel map data will be written.|
**Return value** **Return value**
...@@ -268,11 +211,39 @@ Writes image pixel map data to an area. This API uses a promise to return the op ...@@ -268,11 +211,39 @@ Writes image pixel map data to an area. This API uses a promise to return the op
**Example** **Example**
```js ```js
pixelMap.writePixels(area).then(() => { const color = new ArrayBuffer(96);
console.log("Succeeded in writing pixels."); let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
}).catch((err) => { image.createPixelMap(color, opts)
console.error("Failed to write pixels."); .then( pixelmap => {
}); if (pixelmap == undefined) {
console.info('createPixelMap failed');
expect(false).assertTrue()
done();
}
const area = { pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
var bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1;
}
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 }
}
})
})
.catch(error => {
console.log('error: ' + error);
expect().assertFail();
done();
})
``` ```
### writePixels<sup>7+</sup> ### writePixels<sup>7+</sup>
...@@ -287,7 +258,7 @@ Writes image pixel map data to an area. This API uses a callback to return the o ...@@ -287,7 +258,7 @@ Writes image pixel map data to an area. This API uses a callback to return the o
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------ | ---- | ------------------------------ | | --------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#PositionArea7) | Yes | Area to which the pixel map data will be written. | | area | [PositionArea](#positionarea7) | Yes | Area to which the 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 operation result. If the operation fails, an error message is returned.|
**Example** **Example**
...@@ -401,19 +372,7 @@ Obtains pixel map information about this image. This API uses a callback to retu ...@@ -401,19 +372,7 @@ Obtains pixel map information about this image. This API uses a callback to retu
**Example** **Example**
```js ```js
pixelmap.getImageInfo((imageInfo) => { pixelmap.getImageInfo((imageInfo) => {})
if (imageInfo !== null) {
console.info('TC_024-1 imageInfo is ready')
expect(imageInfo.size.height == 4).assertTrue()
expect(imageInfo.size.width == 6).assertTrue()
expect(imageInfo.pixelFormat == 1).assertTrue()
done()
} else {
console.info('TC_024-1 imageInfo is empty')
expect(false).assertTrue()
done()
}
})
``` ```
### getBytesNumberPerRow<sup>7+</sup> ### getBytesNumberPerRow<sup>7+</sup>
...@@ -433,11 +392,7 @@ Obtains the number of bytes in each line of the image pixel map. ...@@ -433,11 +392,7 @@ Obtains the number of bytes in each line of the image pixel map.
**Example** **Example**
```js ```js
pixelmap.getBytesNumberPerRow().then((num) => { rowCount = pixelmap.getBytesNumberPerRow()
console.info('TC_025 num is ' + num)
expect(num == expectNum).assertTrue()
done()
})
``` ```
### getPixelBytesNumber<sup>7+</sup> ### getPixelBytesNumber<sup>7+</sup>
...@@ -457,11 +412,7 @@ Obtains the total number of bytes of the image pixel map. ...@@ -457,11 +412,7 @@ Obtains the total number of bytes of the image pixel map.
**Example** **Example**
```js ```js
pixelmap.getPixelBytesNumber().then((num) => { pixelBytesNumber = pixelmap.getPixelBytesNumber()
console.info('TC_026 num is ' + num)
expect(num == expectNum).assertTrue()
done()
})
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -481,9 +432,8 @@ Releases this **PixelMap** object. This API uses a promise to return the result. ...@@ -481,9 +432,8 @@ Releases this **PixelMap** object. This API uses a promise to return the result.
**Example** **Example**
```js ```js
pixelmap.release() pixelmap.release().then(() => { })
expect(true).assertTrue() .catch(error => {})
done()
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -503,11 +453,7 @@ Releases this **PixelMap** object. This API uses a callback to return the result ...@@ -503,11 +453,7 @@ Releases this **PixelMap** object. This API uses a callback to return the result
**Example** **Example**
```js ```js
pixelmap.release(()=>{ pixelmap.release(()=>{ })
expect(true).assertTrue();
console.log('TC_027-1 success');
done();
})
``` ```
## image.createImageSource ## image.createImageSource
...@@ -526,9 +472,9 @@ Creates an **ImageSource** instance based on the URI. ...@@ -526,9 +472,9 @@ Creates an **ImageSource** instance based on the URI.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------- | --------------------------------------- | | --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **null** otherwise.| | [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
**Example** **Example**
...@@ -552,9 +498,9 @@ Creates an **ImageSource** instance based on the file descriptor. ...@@ -552,9 +498,9 @@ Creates an **ImageSource** instance based on the file descriptor.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------- | --------------------------------------- | | --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **null** otherwise.| | [ImageSource](#imagesource) | Returns the **ImageSource** instance if the operation is successful; returns **undefined** otherwise.|
**Example** **Example**
...@@ -590,20 +536,7 @@ Obtains information about an image with the specified index. This API uses a cal ...@@ -590,20 +536,7 @@ Obtains information about an image with the specified index. This API uses a cal
**Example** **Example**
```js ```js
it('TC_046', 0, async function (done) { imageSourceApi.getImageInfo(0,(error, imageInfo) => {})
const imageSourceApi = image.createImageSource('/sdcard/test.jpg');
if (imageSourceApi == null) {
console.info('TC_046 create image source failed');
expect(false).assertTrue();
done();
} else {
imageSourceApi.getImageInfo(0,(error, imageInfo) => {
console.info('TC_046 imageInfo');
expect(imageInfo !== null).assertTrue();
done();
})
}
})
``` ```
### getImageInfo ### getImageInfo
...@@ -623,11 +556,7 @@ Obtains information about this image. This API uses a callback to return the inf ...@@ -623,11 +556,7 @@ Obtains information about this image. This API uses a callback to return the inf
**Example** **Example**
```js ```js
imageSourceApi.getImageInfo(imageInfo => { imageSourceApi.getImageInfo(imageInfo => {})
console.info('TC_045 imageInfo');
expect(imageInfo !== null).assertTrue();
done();
})
``` ```
### getImageInfo ### getImageInfo
...@@ -654,11 +583,8 @@ Obtains information about an image with the specified index. This API uses a pro ...@@ -654,11 +583,8 @@ Obtains information about an image with the specified index. This API uses a pro
```js ```js
imageSourceApi.getImageInfo(0) imageSourceApi.getImageInfo(0)
.then(imageInfo => { .then(imageInfo => {})
console.info('TC_047 imageInfo'); .catch(error => {})
expect(imageInfo !== null).assertTrue();
done();
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -685,7 +611,9 @@ Obtains the value of a property with the specified index in this image. This API ...@@ -685,7 +611,9 @@ Obtains the value of a property with the specified index in this image. This API
**Example** **Example**
```js ```js
const w = imageSourceApi.getImageProperty("ImageWidth") imageSourceApi.getImageProperty("BitsPerSample")
.then(data => {})
.catch(error => {})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -706,7 +634,7 @@ Obtains the value of a property with the specified index in this image. This API ...@@ -706,7 +634,7 @@ Obtains the value of a property with the specified index in this image. This API
**Example** **Example**
```js ```js
const w = imageSourceApi.getImageProperty("ImageWidth",w=>{}) imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -728,12 +656,12 @@ Obtains the value of a property in this image. This API uses a callback to retur ...@@ -728,12 +656,12 @@ Obtains the value of a property in this image. This API uses a callback to retur
**Example** **Example**
```js ```js
imageSourceApi.getImageProperty("ImageWidth",PropertyOptions,(w)=>{}) imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
createPixelMap(index: number, options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
Creates a **PixelMap** object based on image decoding parameters. This API uses a callback to return the result. Creates a **PixelMap** object based on image decoding parameters. This API uses a callback to return the result.
...@@ -741,58 +669,46 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses ...@@ -741,58 +669,46 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------- | ------------------------------------- | ---- | -------------------- | | ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. | | options | [DecodingOptions](#decodingoptions7) | No | Image decoding parameters.|
| index | number | Yes | Image index. |
| AsyncCallback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the operation result.| **Return value**
| Type | Description |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise used to return the **PixelMap** object.|
**Example** **Example**
```js ```js
imageSourceApi.createPixelMap().then(pixelmap => { imageSourceApi.createPixelMap().then(pixelmap => {})
console.info('TC_050-11 createPixelMap '); .catch(error => {})
expect(pixelmap !== null ).assertTrue();
done();
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void createPixelMap(callback: AsyncCallback\<PixelMap>): void
Creates a **PixelMap** object based on image decoding parameters. This API uses a callback to return the result. Creates a **PixelMap** object based on the default parameters. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------------- |
| options | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. | | callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.|
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the operation result.|
**Example** **Example**
```js ```js
let decodingOptions = { imageSourceApi.createPixelMap(pixelmap => {})
sampleSize:1,
editable: true,
desiredSize:{ width:1, height:2},
rotateDegrees:10,
desiredPixelFormat:1,
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
};
imageSourceApi.createPixelMap(0,decodingOptions, pixelmap => {
console.info('TC_050-1 createPixelMap ');
expect(pixelmap !== null ).assertTrue();
done();
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
createPixelMap(opts: DecodingOptions, callback: AsyncCallback\<PixelMap>): void createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
Creates a **PixelMap** object based on image decoding parameters. This API uses a callback to return the result. Creates a **PixelMap** object based on image decoding parameters. This API uses a callback to return the result.
...@@ -800,28 +716,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses ...@@ -800,28 +716,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------------- |
| opts | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. | | options | [DecodingOptions](#decodingoptions7) | Yes | Image decoding parameters. |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the operation result.| | callback | AsyncCallback<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.|
**Example** **Example**
```js ```js
let decodingOptions = { imageSourceApi.createPixelMap(decodingOptions, pixelmap => {})
sampleSize:1,
editable: true,
desiredSize:{ width:1, height:2},
rotateDegrees:10,
desiredPixelFormat:1,
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
index:1
};
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.info('TC_050-1 createPixelMap ');
expect(pixelmap !== null ).assertTrue();
done();
})
``` ```
### release ### release
...@@ -841,12 +744,7 @@ Releases this **ImageSource** instance. This API uses a callback to return the r ...@@ -841,12 +744,7 @@ Releases this **ImageSource** instance. This API uses a callback to return the r
**Example** **Example**
```js ```js
imageSourceApi.release(() => { imageSourceApi.release(() => {})
console.info('TC_044-1 Success');
expect(true).assertTrue();
done();
})
}
``` ```
### release ### release
...@@ -866,11 +764,7 @@ Releases this **ImageSource** instance. This API uses a promise to return the re ...@@ -866,11 +764,7 @@ Releases this **ImageSource** instance. This API uses a promise to return the re
**Example** **Example**
```js ```js
imageSourceApi.release(() => { imageSourceApi.release().then(()=>{ }).catch(error => {})
console.info('TC_044-1 Success');
expect(true).assertTrue();
done();
})
``` ```
## image.createImagePacker ## image.createImagePacker
...@@ -883,9 +777,9 @@ Creates an **ImagePacker** instance. ...@@ -883,9 +777,9 @@ Creates an **ImagePacker** instance.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------- | ---------------------- | | --------------------------- | --------------------- |
| ImagePacker | **ImagePacker** instance created.| | [ImagePacker](#imagepacker) | **ImagePacker** instance created.|
**Example** **Example**
...@@ -905,7 +799,60 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must ...@@ -905,7 +799,60 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must
### packing ### packing
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback<Array\<number>>): void packing(source: ImageSource, option: PackingOption, callback: AsyncCallback<Array\<ArrayBuffer>>): void
Packs an image. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Image
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | Yes | Image to pack. |
| option | [PackingOption](#packingoption) | Yes | Option for image packing. |
| callback | AsyncCallback<Array\<ArrayBuffer>> | Yes | Callback used to return the packed data.|
**Example**
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
```
### packing
packing(source: ImageSource, option: PackingOption): Promise<Array\<ArrayBuffer>>
Packs an image. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------- | ---- | -------------- |
| source | [ImageSource](#imagesource) | Yes | Image to pack.|
| option | [PackingOption](#packingoption) | Yes | Option for image packing.|
**Return value**
| Type | Description |
| :--------------------------- | :-------------------------------------------- |
| Promise<Array\<ArrayBuffer>> | Promise used to return the packed data.|
**Example**
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { })
.catch(error => {})
```
### packing
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
Packs an image. This API uses a callback to return the result. Packs an image. This API uses a callback to return the result.
...@@ -915,24 +862,20 @@ Packs an image. This API uses a callback to return the result. ...@@ -915,24 +862,20 @@ Packs an image. This API uses a callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ---------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | Yes | Image to pack. | | source | [PixelMap](#pixelmap) | Yes | **PixelMap** object to pack. |
| option | [PackingOption](#packingoption) | Yes | Option for image packing. | | option | [PackingOption](#packingoption) | Yes | Option for image packing. |
| callback | AsyncCallback<Array\<number>> | Yes | Callback used to return the packed data.| | callback | AsyncCallback\<ArrayBuffer> | Yes | Callback used to return the packed data.|
**Example** **Example**
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts, data => { imagePackerApi.packing(pixelMapApi, packOpts, data => {})
console.info('TC_062-1 finished');
expect(data !== null).assertTrue();
done();
})
``` ```
### packing ### packing
packing(source: ImageSource, option: PackingOption): Promise<Array\<number>> packing(source: PixelMap, option: PackingOption): Promise<Array\<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.
...@@ -942,25 +885,22 @@ Packs an image. This API uses a promise to return the result. ...@@ -942,25 +885,22 @@ Packs an image. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------- | ---- | -------------- | | ------ | ------------------------------- | ---- | -------------- |
| source | [ImageSource](#imagesource) | Yes | Image to pack.| | source | [PixelMap](#pixelmap) | Yes | **PixelMap** object to pack.|
| option | [PackingOption](#packingoption) | Yes | Option for image packing.| | option | [PackingOption](#packingoption) | Yes | Option for image packing.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| :---------------------- | :-------------------------------------------- | | :--------------------------- | :-------------------------------------------- |
| Promise<Array\<number>> | Promise used to return the packed data.| | Promise<Array\<ArrayBuffer>> | Promise used to return the packed data.|
**Example** **Example**
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(pixelMapApi, packOpts)
.then( data => { .then( data => { })
console.info('TC_062 finished'); .catch(error => {})
expect(data !== null).assertTrue();
done();
})
``` ```
### release ### release
...@@ -980,10 +920,7 @@ Releases this **ImagePacker** instance. This API uses a callback to return the r ...@@ -980,10 +920,7 @@ Releases this **ImagePacker** instance. This API uses a callback to return the r
**Example** **Example**
```js ```js
imagePackerApi.release(()=>{ imagePackerApi.release(()=>{})
console.info('TC_063-1 release');
expect(true).assertTrue();
done();
``` ```
### release ### release
...@@ -1003,10 +940,8 @@ Releases this **ImagePacker** instance. This API uses a promise to return the re ...@@ -1003,10 +940,8 @@ Releases this **ImagePacker** instance. This API uses a promise to return the re
**Example** **Example**
```js ```js
imagePackerApi.release(); imagePackerApi.release().then(()=>{
console.info('TC_063 release'); }).catch((error)=>{})
expect(true).assertTrue();
done();
``` ```
## PositionArea<sup>7+</sup> ## PositionArea<sup>7+</sup>
...@@ -1015,14 +950,14 @@ Describes area information in an image. ...@@ -1015,14 +950,14 @@ Describes area information in an image.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------ | ------------------ | ---- | ---- | -------------------- | | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| 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 to read. | | 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](#region8) | Yes | No | Region to read or write.| | region | [Region](#region8) | 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
Describes image information. Describes image information.
...@@ -1055,7 +990,7 @@ Enumerates pixel map formats. ...@@ -1055,7 +990,7 @@ Enumerates pixel map formats.
| RGBA_8888 | 3 | RGBA_8888.| | RGBA_8888 | 3 | RGBA_8888.|
| RGB_565 | 2 | RGB_565. | | RGB_565 | 2 | RGB_565. |
## AlphaType<sup>8+</sup> ## AlphaType<sup>9+</sup>
Enumerates alpha types. Enumerates alpha types.
...@@ -1068,7 +1003,7 @@ Enumerates alpha types. ...@@ -1068,7 +1003,7 @@ Enumerates alpha types.
| 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>8+</sup> ## ScaleMode<sup>9+</sup>
Enumerates scale modes. Enumerates scale modes.
...@@ -1085,10 +1020,10 @@ Enumerates scale modes. ...@@ -1085,10 +1020,10 @@ Enumerates scale modes.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------- | ---------------------------------- | ---- | ---- | -------------- | | ----------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType | [AlphaType](#alphatype8) | 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 | [ScaleMode](#scalemode8) | 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>
...@@ -1100,22 +1035,22 @@ Describes the decoding options. ...@@ -1100,22 +1035,22 @@ Describes the decoding options.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- | | ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
| sampleSize | number | Yes | Yes | Thumbnail sampling size.| | sampleSize | number | Yes | Yes | Thumbnail sampling size.|
| rotateDegrees | number | Yes | Yes | Rotation angle. | | rotate | number | Yes | Yes | Rotation angle. |
| editable | boolean | Yes | Yes | Whether the image is editable. | | editable | boolean | Yes | Yes | Whether the image is editable. |
| desiredSize | [Size](#size) | Yes | Yes | Expected output size. | | desiredSize | [Size](#size) | Yes | Yes | Expected output size. |
| desiredRegion | [Region](#region8) | Yes | Yes | Region to decode. | | desiredRegion | [Region](#region7) | Yes | Yes | Region to decode. |
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format for decoding.| | desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format for decoding.|
| index | numer | Yes | Yes | Index of the image to decode. | | index | numer | Yes | Yes | Index of the image to decode. |
## Region<sup>8+</sup> ## Region<sup>7+</sup>
Describes region information. Describes region information.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
| Name| Type | Readable| Writable| Description | | Name| Type | Readable| Writable| Description |
| ---- | ------------- | ---- | ---- | ---------- | | ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | Yes | Yes | Region size.| | size | [Size](#size) | Yes | Yes | Region size. |
| x | number | Yes | Yes | X coordinate of the region.| | x | number | Yes | Yes | X coordinate of the region.|
| y | number | Yes | Yes | Y coordinate of the region.| | y | number | Yes | Yes | Y coordinate of the region.|
...@@ -1145,6 +1080,8 @@ Describes image properties. ...@@ -1145,6 +1080,8 @@ 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
| Name | Default Value | Description | | Name | Default Value | Description |
| ----------------- | ----------------- | -------------------- | | ----------------- | ----------------- | -------------------- |
| BITS_PER_SAMPLE | "BitsPerSample" | Number of bytes in each pixel. | | BITS_PER_SAMPLE | "BitsPerSample" | Number of bytes in each pixel. |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册