提交 fa2d4b8a 编写于 作者: X xu-rui-w

文档整改

Signed-off-by: Nxu-rui-w <xurui101@huawei.com>
上级 3479a3a8
......@@ -2,12 +2,10 @@
> **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
## 导入模块
```
```js
import image from '@ohos.multimedia.image';
```
......@@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors | ArrayBuffer | 是 | 颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
| colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
**返回值:**
......@@ -34,9 +32,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
**示例:**
```js
image.createPixelMap(Color, opts)
.then((pixelmap) => {
})
const color = new ArrayBuffer(96);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
.then((pixelmap) => {
})
```
## image.createPixelMap<sup>8+</sup>
......@@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors | ArrayBuffer | 是 | 颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 属性。 |
| colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializationOptions](#initializationoptions8) | 是 | 属性。 |
| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 |
**示例:**
```js
image.createPixelMap(Color, opts, (pixelmap) => {
})
const color = new ArrayBuffer(96);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => {
})
```
## PixelMap<sup>7+</sup>
......@@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => {
### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。<br/>**系统能力:** SystemCapability.Multimedia.Image |
**系统能力:** SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。 |
### readPixelsToBuffer<sup>7+</sup>
......@@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
**示例:**
```js
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
//符合条件则进入
}).catch(error => {
//不符合条件则进入
})
pixelmap.readPixelsToBuffer(ReadBuffer).then(() => {
console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}).catch(error => {
console.log('readPixelsToBuffer failed.'); //不符合条件则进入
})
```
### readPixelsToBuffer<sup>7+</sup>
......@@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:**
```js
pixelmap.readPixelsToBuffer(readBuffer, () => {
})
pixelmap.readPixelsToBuffer(ReadBuffer, (err, res) => {
if(err) {
console.log('readPixelsToBuffer failed.'); //不符合条件则进入
} else {
console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}
})
```
### readPixels<sup>7+</sup>
......@@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\<void>
**示例:**
```js
pixelmap.readPixels(area).then((data) => {
//符合条件则进入
}).catch(error => {
//不符合条件则进入
})
pixelmap.readPixels(Area).then((data) => {
console.log('readPixels succeeded.'); //符合条件则进入
}).catch(error => {
console.log('readPixels failed.'); //不符合条件则进入
})
```
### readPixels<sup>7+</sup>
......@@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
```js
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
if(pixelmap == undefined){
console.info('createPixelMap failed');
expect(false).assertTrue();
done();
}else{
const area = { pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}
pixelmap.readPixels(area, () => {
console.info('readPixels success');
})
}
if(pixelmap == undefined){
console.info('createPixelMap failed.');
} else {
const area = { pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }};
pixelmap.readPixels(area, () => {
console.info('readPixels success');
})
}
})
```
......@@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
.then( pixelmap => {
if (pixelmap == undefined) {
console.info('createPixelMap failed');
expect(false).assertTrue()
done();
console.info('createPixelMap failed.');
}
const area = { pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
var bufferArr = new Uint8Array(area.pixels);
let bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1;
}
......@@ -240,11 +245,8 @@ image.createPixelMap(color, opts)
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
})
})
.catch(error => {
}).catch(error => {
console.log('error: ' + error);
expect().assertFail();
done();
})
```
......@@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 |
| callback: | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 |
| callback: | AsyncCallback\<void> | 是 | 获取回调,失败时error会返回错误信息。 |
**示例:**
```js
pixelmap.writePixels(area, () => {
const readArea = {
pixels: new ArrayBuffer(20),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
})
pixelmap.writePixels(Area, (error) => {
if (error!=undefined) {
console.info('writePixels failed.');
} else {
const readArea = {
pixels: new ArrayBuffer(20),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
}
})
```
### writeBufferToPixels<sup>7+</sup>
......@@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
**示例:**
```js
pixelMap.writeBufferToPixels(colorBuffer).then(() => {
PixelMap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => {
console.error("Failed to write data from a buffer to a PixelMap.");
});
})
```
### writeBufferToPixels<sup>7+</sup>
......@@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:**
```js
pixelMap.writeBufferToPixels(colorBuffer, function(err) {
PixelMap.writeBufferToPixels(color, function(err) {
if (err) {
console.error("Failed to write data from a buffer to a PixelMap.");
return;
}
console.log("Succeeded in writing data from a buffer to a PixelMap.");
} else {
console.log("Succeeded in writing data from a buffer to a PixelMap.");
}
});
```
......@@ -350,7 +357,7 @@ getImageInfo(): Promise\<ImageInfo>
**示例:**
```js
pixelMap.getImageInfo().then(function(info) {
PixelMap.getImageInfo().then(function(info) {
console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => {
console.error("Failed to obtain the image pixel map information.");
......@@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:**
```js
pixelmap.getImageInfo((imageInfo) => {})
pixelmap.getImageInfo((imageInfo) => {
console.log("getImageInfo succeeded.");
}).catch((err) => {
console.error("getImageInfo failed.");
})
```
### getBytesNumberPerRow<sup>7+</sup>
......@@ -394,7 +405,9 @@ getBytesNumberPerRow(): number
**示例:**
```js
rowCount = pixelmap.getBytesNumberPerRow()
image.createPixelMap(clolr, opts, (err,pixelmap) => {
let rowCount = pixelmap.getBytesNumberPerRow();
})
```
### getPixelBytesNumber<sup>7+</sup>
......@@ -414,7 +427,7 @@ getPixelBytesNumber(): number
**示例:**
```js
pixelBytesNumber = pixelmap.getPixelBytesNumber()
let pixelBytesNumber = pixelmap.getPixelBytesNumber();
```
### release<sup>7+</sup>
......@@ -434,8 +447,13 @@ release():Promise\<void>
**示例:**
```js
pixelmap.release().then(() => { })
.catch(error => {})
image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
```
### release<sup>7+</sup>
......@@ -455,7 +473,13 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```js
pixelmap.release(()=>{ })
image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
```
## image.createImageSource
......@@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource
**示例:**
```js
const imageSourceApi = image.createImageSource(0)
const imageSourceApi = image.createImageSource(0);
```
## ImageSource
......@@ -517,9 +541,11 @@ const imageSourceApi = image.createImageSource(0)
### 属性
**系统能力:** SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。<br/>**系统能力:** SystemCapability.Multimedia.Image |
| supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。 |
### getImageInfo
......@@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
**示例:**
```js
imageSourceApi.getImageInfo(0,(error, imageInfo) => {})
imageSourceApi.getImageInfo(0,(error, imageInfo) => {
if(error) {
console.log('getImageInfo failed.');
} else {
console.log('getImageInfo succeeded.');
}
})
```
### getImageInfo
......@@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:**
```js
imageSourceApi.getImageInfo(imageInfo => {})
imageSourceApi.getImageInfo(imageInfo => {
console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
```
### getImageInfo
......@@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\<ImageInfo>
```js
imageSourceApi.getImageInfo(0)
.then(imageInfo => {})
.catch(error => {})
.then(imageInfo => {
console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
```
### getImageProperty<sup>7+</sup>
......@@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string
```js
imageSourceApi.getImageProperty("BitsPerSample")
.then(data => {})
.catch(error => {})
.then(data => {
console.log('getImageProperty succeeded.');
}).catch(error => {
console.log('getImageProperty failed.');
})
```
### getImageProperty<sup>7+</sup>
......@@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void
**示例:**
```js
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {})
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {
if(error) {
console.log('getImageProperty failed.');
} else {
console.log('getImageProperty succeeded.');
}
})
```
### getImageProperty<sup>7+</sup>
......@@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
**示例:**
```js
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {})
imageSourceApi.getImageProperty("BitsPerSample",Property,(error,data) => {
if(error) {
console.log('getImageProperty failed.');
} else {
console.log('getImageProperty succeeded.');
}
})
```
### createPixelMap<sup>7+</sup>
......@@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
**示例:**
```js
imageSourceApi.createPixelMap().then(pixelmap => {})
.catch(error => {})
imageSourceApi.createPixelMap().then(pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
```
### createPixelMap<sup>7+</sup>
......@@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void
**示例:**
```js
imageSourceApi.createPixelMap(pixelmap => {})
imageSourceApi.createPixelMap(pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
```
### createPixelMap<sup>7+</sup>
......@@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
**示例:**
```js
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {})
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
```
### release
......@@ -747,7 +812,11 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```js
imageSourceApi.release(() => {})
imageSourceApi.release(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
### release
......@@ -767,7 +836,11 @@ release(): Promise\<void>
**示例:**
```js
imageSourceApi.release().then(()=>{ }).catch(error => {})
imageSourceApi.release().then(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
## image.createImagePacker
......@@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker();
### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。<br/>**系统能力:** SystemCapability.Multimedia.Image |
**系统能力:** SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。 |
### packing
......@@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 |
| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 |
**示例:**
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
let packOpts = { format:"image/jpeg", quality:98 };
imagePackerApi.packing(ImageSourceApi, packOpts, data => {})
```
### packing
......@@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { })
.catch(error => {})
imagePackerApi.packing(ImageSourceApi, packOpts)
.then( data => {
console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
```
### packing<sup>8+</sup>
......@@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts, data => {})
imagePackerApi.packing(PixelMapApi, packOpts, data => {
console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
```
### packing<sup>8+</sup>
......@@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------- | ---- | -------------- |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------- | ---- | ------------------ |
| source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
**返回值:**
......@@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
```js
let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts)
.then( data => { })
.catch(error => {})
imagePackerApi.packing(PixelMapApi, packOpts)
.then( data => {
console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
```
### release
......@@ -923,7 +1008,11 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```js
imagePackerApi.release(()=>{})
imagePackerApi.release(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
### release
......@@ -943,8 +1032,390 @@ release(): Promise\<void>
**示例:**
```js
imagePackerApi.release().then(()=>{
}).catch((error)=>{})
imagePackerApi.release().then(()=>{
console.log('release succeeded.');
}).catch((error)=>{
console.log('release failed.');
})
```
## image.createImageReceiver<sup>9+</sup>
createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
通过宽、高、图片格式、容量创建ImageReceiver实例。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- |
| width | number | 是 | 图像的默认宽度。 |
| height | number | 是 | 图像的默认高度。 |
| format | number | 是 | 图像格式。 |
| capacity | number | 是 | 同时访问的最大图像数。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
**示例:**
```js
var receiver = image.createImageReceiver(8192, 8, 4, 8);
```
## ImageReceiver<sup>9+</sup>
图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。
在调用以下方法前需要先创建ImageReceiver实例。
### 属性
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup> | [Size](#size) | 是 | 否 | 图片大小。 |
| capacity<sup>9+</sup> | number | 是 | 否 | 同时访问的图像数。 |
| format<sup>9+</sup> | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 |
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(callback: AsyncCallback\<string>): void
用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是 | 回调函数,返回surface id。 |
**示例:**
```js
receiver.getReceivingSurfaceId((err, id) => {
if(err) {
console.log('getReceivingSurfaceId failed.');
} else {
console.log('getReceivingSurfaceId succeeded.');
}
});
```
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(): Promise\<string>
用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
**示例:**
```js
receiver.getReceivingSurfaceId().then( id => {
console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
console.log('getReceivingSurfaceId failed.');
})
```
### readLatestImage<sup>9+</sup>
readLatestImage(callback: AsyncCallback\<Image>): void
从ImageReceiver读取最新的图片,并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回最新图像。 |
**示例:**
```js
receiver.readLatestImage((err, img) => {
if(err) {
console.log('readLatestImage failed.');
} else {
console.log('readLatestImage succeeded.');
}
});
```
### readLatestImage<sup>9+</sup>
readLatestImage(): Promise\<Image>
从ImageReceiver读取最新的图片,并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise<[Image](#image8)> | 异步返回最新图片。 |
**示例:**
```js
receiver.readLatestImage().then(img => {
console.log('readLatestImage succeeded.');
}).catch(error => {
console.log('readLatestImage failed.');
})
```
### readNextImage<sup>9+</sup>
readNextImage(callback: AsyncCallback\<Image>): void
从ImageReceiver读取下一张图片,并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回下一张图片。 |
**示例:**
```js
receiver.readNextImage((err, img) => {
if(err) {
console.log('readNextImage failed.');
} else {
console.log('readNextImage succeeded.');
}
});
```
### readNextImage<sup>9+</sup>
readNextImage(): Promise\<Image>
从ImageReceiver读取下一张图片,并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ------------------------- | -------------------- |
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
**示例:**
```js
receiver.readNextImage().then(img => {
console.log('readNextImage succeeded.');
}).catch(error => {
console.log('readNextImage failed.');
})
```
### on('imageArrival')<sup>9+</sup>
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
接收图片时注册回调。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| type | string | 是 | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
| callback | AsyncCallback\<void> | 是 | 注册的事件回调。 |
**示例:**
```js
receiver.on('imageArrival', () => {})
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
释放ImageReceiver实例并使用回调返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回操作结果。 |
**示例:**
```js
receiver.release(() => {})
```
### release<sup>9+</sup>
release(): Promise\<void>
释放ImageReceiver实例并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
**示例:**
```js
receiver.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
## Image<sup>9+</sup>
提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)[readLatestImage](#readlatestimage9)接口时会返回image。
### 属性
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect<sup>9+</sup> | [Region](#region7) | 是 | 是 | 要裁剪的图像区域。 |
| size<sup>9+</sup> | [Size](#size) | 是 | 否 | 图像大小。 |
| format<sup>9+</sup> | number | 是 | 否 | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 |
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | --------------------------------------- | ---- | -------------------- |
| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 |
| callback | AsyncCallback<[Component](#component9)> | 是 | 用于返回组件缓冲区。 |
**示例:**
```js
img.getComponent(4, (err, component) => {
if(err) {
console.log('getComponent failed.');
} else {
console.log('getComponent succeeded.');
}
})
```
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType): Promise\<Component>
根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------- | ---- | ---------------- |
| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------- |
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
**示例:**
```js
img.getComponent(4).then(component => { })
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
释放当前图像并使用callback返回结果。
在接收另一个图像前必须先释放对应资源。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是 | 返回操作结果。 |
**示例:**
```js
img.release(() =>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
### release<sup>9+</sup>
release(): Promise\<void>
释放当前图像并使用Promise方式返回结果。
在接收另一个图像前必须先释放对应资源。
**系统能力:** SystemCapability.Multimedia.Image.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
**示例:**
```js
img.release().then(() =>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
## PositionArea<sup>7+</sup>
......@@ -957,7 +1428,7 @@ release(): Promise\<void>
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer | 是 | 否 | 像素。 |
| offset | number | 是 | 否 | 偏移量。 |
| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 |
| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 |
| region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 |
## ImageInfo
......@@ -983,7 +1454,7 @@ release(): Promise\<void>
## PixelMapFormat<sup>7+</sup>
枚举,像素格式。
枚举,图片像素格式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
......@@ -995,7 +1466,7 @@ release(): Promise\<void>
## AlphaType<sup>9+</sup>
枚举,透明度
枚举,图像的透明度类型
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
......@@ -1008,7 +1479,7 @@ release(): Promise\<void>
## ScaleMode<sup>9+</sup>
枚举,缩略值
枚举,图像的缩放模式
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
......@@ -1019,19 +1490,21 @@ release(): Promise\<void>
## InitializationOptions<sup>8+</sup>
PixelMap的初始化选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 |
| editable | boolean | 是 | 是 | 是否可编辑。 |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 |
| size | [Size](#size) | 是 | 是 | 创建图片大小。 |
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 |
| editable | boolean | 是 | 是 | 是否可编辑。 |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 |
| size | [Size](#size) | 是 | 是 | 创建图片大小。 |
## DecodingOptions<sup>7+</sup>
解码设置选项。
图像解码设置选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
......@@ -1043,7 +1516,7 @@ release(): Promise\<void>
| desiredSize | [Size](#size) | 是 | 是 | 期望输出大小。 |
| desiredRegion | [Region](#region7) | 是 | 是 | 解码区域。 |
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 解码的像素格式。 |
| index | numer | 是 | 是 | 解码图片序号 |
| index | number | 是 | 是 | 解码图片序号 |
## Region<sup>7+</sup>
......@@ -1066,7 +1539,7 @@ release(): Promise\<void>
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | -------------- |
| format | string | 是 | 是 | 目标格式。 |
| quality | number | 是 | 是 | 目标图片质量。 |
| quality | number | 是 | 是 | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
## GetImagePropertyOptions<sup>7+</sup>
......@@ -1096,3 +1569,40 @@ release(): Promise\<void>
| GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 |
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 |
## ImageFormat<sup>9+</sup>
枚举,图片格式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 默认值 | 描述 |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000 | YCBCR422半平面格式。 |
| JPEG | 2000 | JPEG编码格式。 |
## ComponentType<sup>9+</sup>
枚举,图像的组件类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
| 名称 | 默认值 | 描述 |
| ----- | ------ | ----------- |
| YUV_Y | 1 | 亮度信息。 |
| YUV_U | 2 | 色度信息。 |
| YUV_V | 3 | 色度信息。 |
| JPEG | 4 | Jpeg 类型。 |
## Component<sup>9+</sup>
描述图像颜色分量。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
| componentType | [ComponentType](#componenttype9) | 是 | 否 | 组件类型。 |
| rowStride | number | 是 | 否 | 行距。 |
| pixelStride | number | 是 | 否 | 像素间距。 |
| byteBuffer | ArrayBuffer | 是 | 否 | 组件缓冲区。 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册