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

!6199 image文档整改

Merge pull request !6199 from 徐蕊w/OpenHarmony-3.1-Release
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
> **说明:** > **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
## 导入模块 ## 导入模块
``` ```js
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
...@@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors | ArrayBuffer | 是 | 颜色数组。 | | colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | | options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
**返回值:** **返回值:**
...@@ -34,9 +32,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -34,9 +32,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
**示例:** **示例:**
```js ```js
image.createPixelMap(Color, opts) const color = new ArrayBuffer(96);
.then((pixelmap) => { let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
}) image.createPixelMap(color, opts)
.then((pixelmap) => {
})
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
...@@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As ...@@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors | ArrayBuffer | 是 | 颜色数组。 | | colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 属性。 | | options | [InitializationOptions](#initializationoptions8) | 是 | 属性。 |
| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 |
**示例:** **示例:**
```js ```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> ## PixelMap<sup>7+</sup>
...@@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => { ...@@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => {
### 属性 ### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 | **系统能力:** SystemCapability.Multimedia.Image
| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。<br/>**系统能力:** SystemCapability.Multimedia.Image | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。 |
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> ...@@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(ReadBuffer).then(() => {
//符合条件则进入 console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}).catch(error => { }).catch(error => {
//不符合条件则进入 console.log('readPixelsToBuffer failed.'); //不符合条件则进入
}) })
``` ```
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelmap.readPixelsToBuffer(readBuffer, () => { pixelmap.readPixelsToBuffer(ReadBuffer, (err, res) => {
}) if(err) {
console.log('readPixelsToBuffer failed.'); //不符合条件则进入
} else {
console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}
})
``` ```
### readPixels<sup>7+</sup> ### readPixels<sup>7+</sup>
...@@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\<void> ...@@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.readPixels(area).then((data) => { pixelmap.readPixels(Area).then((data) => {
//符合条件则进入 console.log('readPixels succeeded.'); //符合条件则进入
}).catch(error => { }).catch(error => {
//不符合条件则进入 console.log('readPixels failed.'); //不符合条件则进入
}) })
``` ```
### readPixels<sup>7+</sup> ### readPixels<sup>7+</sup>
...@@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
```js ```js
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => { image.createPixelMap(color, opts, (err, pixelmap) => {
if(pixelmap == undefined){ if(pixelmap == undefined){
console.info('createPixelMap failed'); console.info('createPixelMap failed.');
expect(false).assertTrue(); } else {
done(); const area = { pixels: new ArrayBuffer(8),
}else{ offset: 0,
const area = { pixels: new ArrayBuffer(8), stride: 8,
offset: 0, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }};
stride: 8, pixelmap.readPixels(area, () => {
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} console.info('readPixels success');
pixelmap.readPixels(area, () => { })
console.info('readPixels success'); }
})
}
}) })
``` ```
...@@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } ...@@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts) image.createPixelMap(color, opts)
.then( pixelmap => { .then( pixelmap => {
if (pixelmap == undefined) { if (pixelmap == undefined) {
console.info('createPixelMap failed'); console.info('createPixelMap failed.');
expect(false).assertTrue()
done();
} }
const area = { pixels: new ArrayBuffer(8), const area = { pixels: new ArrayBuffer(8),
offset: 0, offset: 0,
stride: 8, stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } 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++) { for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
...@@ -240,11 +245,8 @@ image.createPixelMap(color, opts) ...@@ -240,11 +245,8 @@ image.createPixelMap(color, opts)
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
} }
}) })
}) }).catch(error => {
.catch(error => {
console.log('error: ' + error); console.log('error: ' + error);
expect().assertFail();
done();
}) })
``` ```
...@@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------ | ---- | ------------------------------ | | --------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | | area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 |
| callback: | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | | callback: | AsyncCallback\<void> | 是 | 获取回调,失败时error会返回错误信息。 |
**示例:** **示例:**
```js ```js
pixelmap.writePixels(area, () => { pixelmap.writePixels(Area, (error) => {
const readArea = { if (error!=undefined) {
pixels: new ArrayBuffer(20), console.info('writePixels failed.');
offset: 0, } else {
stride: 8, const readArea = {
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, pixels: new ArrayBuffer(20),
} offset: 0,
}) stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
}
})
``` ```
### writeBufferToPixels<sup>7+</sup> ### writeBufferToPixels<sup>7+</sup>
...@@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void> ...@@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
pixelMap.writeBufferToPixels(colorBuffer).then(() => { PixelMap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((err) => {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
}); })
``` ```
### writeBufferToPixels<sup>7+</sup> ### writeBufferToPixels<sup>7+</sup>
...@@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelMap.writeBufferToPixels(colorBuffer, function(err) { PixelMap.writeBufferToPixels(color, function(err) {
if (err) { if (err) {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
return; return;
} } else {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}
}); });
``` ```
...@@ -350,7 +357,7 @@ getImageInfo(): Promise\<ImageInfo> ...@@ -350,7 +357,7 @@ getImageInfo(): Promise\<ImageInfo>
**示例:** **示例:**
```js ```js
pixelMap.getImageInfo().then(function(info) { PixelMap.getImageInfo().then(function(info) {
console.log("Succeeded in obtaining the image pixel map information."); console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => { }).catch((err) => {
console.error("Failed to obtain the image pixel map information."); console.error("Failed to obtain the image pixel map information.");
...@@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
pixelmap.getImageInfo((imageInfo) => {}) pixelmap.getImageInfo((imageInfo) => {
console.log("getImageInfo succeeded.");
}).catch((err) => {
console.error("getImageInfo failed.");
})
``` ```
### getBytesNumberPerRow<sup>7+</sup> ### getBytesNumberPerRow<sup>7+</sup>
...@@ -394,7 +405,9 @@ getBytesNumberPerRow(): number ...@@ -394,7 +405,9 @@ getBytesNumberPerRow(): number
**示例:** **示例:**
```js ```js
rowCount = pixelmap.getBytesNumberPerRow() image.createPixelMap(clolr, opts, (err,pixelmap) => {
let rowCount = pixelmap.getBytesNumberPerRow();
})
``` ```
### getPixelBytesNumber<sup>7+</sup> ### getPixelBytesNumber<sup>7+</sup>
...@@ -414,7 +427,7 @@ getPixelBytesNumber(): number ...@@ -414,7 +427,7 @@ getPixelBytesNumber(): number
**示例:** **示例:**
```js ```js
pixelBytesNumber = pixelmap.getPixelBytesNumber() let pixelBytesNumber = pixelmap.getPixelBytesNumber();
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -434,8 +447,13 @@ release():Promise\<void> ...@@ -434,8 +447,13 @@ release():Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.release().then(() => { }) image.createPixelMap(color, opts, (pixelmap) => {
.catch(error => {}) pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -455,7 +473,13 @@ release(callback: AsyncCallback\<void>): void ...@@ -455,7 +473,13 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelmap.release(()=>{ }) image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
``` ```
## image.createImageSource ## image.createImageSource
...@@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource ...@@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource
**示例:** **示例:**
```js ```js
const imageSourceApi = image.createImageSource(0) const imageSourceApi = image.createImageSource(0);
``` ```
## ImageSource ## ImageSource
...@@ -517,9 +541,11 @@ const imageSourceApi = image.createImageSource(0) ...@@ -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 ### getImageInfo
...@@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void ...@@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
imageSourceApi.getImageInfo(0,(error, imageInfo) => {}) imageSourceApi.getImageInfo(0,(error, imageInfo) => {
if(error) {
console.log('getImageInfo failed.');
} else {
console.log('getImageInfo succeeded.');
}
})
``` ```
### getImageInfo ### getImageInfo
...@@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
imageSourceApi.getImageInfo(imageInfo => {}) imageSourceApi.getImageInfo(imageInfo => {
console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
``` ```
### getImageInfo ### getImageInfo
...@@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\<ImageInfo> ...@@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\<ImageInfo>
```js ```js
imageSourceApi.getImageInfo(0) imageSourceApi.getImageInfo(0)
.then(imageInfo => {}) .then(imageInfo => {
.catch(error => {}) console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string ...@@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string
```js ```js
imageSourceApi.getImageProperty("BitsPerSample") imageSourceApi.getImageProperty("BitsPerSample")
.then(data => {}) .then(data => {
.catch(error => {}) console.log('getImageProperty succeeded.');
}).catch(error => {
console.log('getImageProperty failed.');
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void ...@@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void
**示例:** **示例:**
```js ```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> ### getImageProperty<sup>7+</sup>
...@@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa ...@@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
**示例:** **示例:**
```js ```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> ### createPixelMap<sup>7+</sup>
...@@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap> ...@@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap().then(pixelmap => {}) imageSourceApi.createPixelMap().then(pixelmap => {
.catch(error => {}) console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void ...@@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap(pixelmap => {}) imageSourceApi.createPixelMap(pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo ...@@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {}) imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### release ### release
...@@ -747,7 +812,11 @@ release(callback: AsyncCallback\<void>): void ...@@ -747,7 +812,11 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
imageSourceApi.release(() => {}) imageSourceApi.release(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
### release ### release
...@@ -767,7 +836,11 @@ release(): Promise\<void> ...@@ -767,7 +836,11 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
imageSourceApi.release().then(()=>{ }).catch(error => {}) imageSourceApi.release().then(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
## image.createImagePacker ## image.createImagePacker
...@@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker(); ...@@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker();
### 属性 ### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 | **系统能力:** SystemCapability.Multimedia.Image
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。<br/>**系统能力:** SystemCapability.Multimedia.Image | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。 |
### packing ### packing
...@@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr ...@@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
| -------- | ---------------------------------- | ---- | ---------------------------------- | | -------- | ---------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | | source | [ImageSource](#imagesource) | 是 | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | | option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 | | callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 |
**示例:** **示例:**
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:"image/jpeg", quality:98 };
imagePackerApi.packing(imageSourceApi, packOpts, data => {}) imagePackerApi.packing(ImageSourceApi, packOpts, data => {})
``` ```
### packing ### packing
...@@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> ...@@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(ImageSourceApi, packOpts)
.then( data => { }) .then( data => {
.catch(error => {}) console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
``` ```
### packing<sup>8+</sup> ### packing<sup>8+</sup>
...@@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB ...@@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } 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> ### packing<sup>8+</sup>
...@@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------- | ---- | -------------- | | ------ | ------------------------------- | ---- | ------------------ |
| source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 | | source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | | option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
**返回值:** **返回值:**
...@@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts) imagePackerApi.packing(PixelMapApi, packOpts)
.then( data => { }) .then( data => {
.catch(error => {}) console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
``` ```
### release ### release
...@@ -923,7 +1008,11 @@ release(callback: AsyncCallback\<void>): void ...@@ -923,7 +1008,11 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
imagePackerApi.release(()=>{}) imagePackerApi.release(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
### release ### release
...@@ -943,8 +1032,390 @@ release(): Promise\<void> ...@@ -943,8 +1032,390 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
imagePackerApi.release().then(()=>{ imagePackerApi.release().then(()=>{
}).catch((error)=>{}) 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> ## PositionArea<sup>7+</sup>
...@@ -957,7 +1428,7 @@ release(): Promise\<void> ...@@ -957,7 +1428,7 @@ release(): Promise\<void>
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer | 是 | 否 | 像素。 | | pixels | ArrayBuffer | 是 | 否 | 像素。 |
| offset | number | 是 | 否 | 偏移量。 | | offset | number | 是 | 否 | 偏移量。 |
| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 | | stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 |
| region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 | | region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 |
## ImageInfo ## ImageInfo
...@@ -983,7 +1454,7 @@ release(): Promise\<void> ...@@ -983,7 +1454,7 @@ release(): Promise\<void>
## PixelMapFormat<sup>7+</sup> ## PixelMapFormat<sup>7+</sup>
枚举,像素格式。 枚举,图片像素格式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -995,7 +1466,7 @@ release(): Promise\<void> ...@@ -995,7 +1466,7 @@ release(): Promise\<void>
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
枚举,透明度 枚举,图像的透明度类型
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1008,7 +1479,7 @@ release(): Promise\<void> ...@@ -1008,7 +1479,7 @@ release(): Promise\<void>
## ScaleMode<sup>9+</sup> ## ScaleMode<sup>9+</sup>
枚举,缩略值 枚举,图像的缩放模式
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1019,19 +1490,21 @@ release(): Promise\<void> ...@@ -1019,19 +1490,21 @@ release(): Promise\<void>
## InitializationOptions<sup>8+</sup> ## InitializationOptions<sup>8+</sup>
PixelMap的初始化选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ---------------------------------- | ---- | ---- | -------------- | | ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | | alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 |
| editable | boolean | 是 | 是 | 是否可编辑。 | | editable | boolean | 是 | 是 | 是否可编辑。 |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | | scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 |
| size | [Size](#size) | 是 | 是 | 创建图片大小。 | | size | [Size](#size) | 是 | 是 | 创建图片大小。 |
## DecodingOptions<sup>7+</sup> ## DecodingOptions<sup>7+</sup>
解码设置选项。 图像解码设置选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1066,7 +1539,7 @@ release(): Promise\<void> ...@@ -1066,7 +1539,7 @@ release(): Promise\<void>
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | -------------- | | ------- | ------ | ---- | ---- | -------------- |
| format | string | 是 | 是 | 目标格式。 | | format | string | 是 | 是 | 目标格式。 |
| quality | number | 是 | 是 | 目标图片质量。 | | quality | number | 是 | 是 | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
## GetImagePropertyOptions<sup>7+</sup> ## GetImagePropertyOptions<sup>7+</sup>
...@@ -1096,3 +1569,40 @@ release(): Promise\<void> ...@@ -1096,3 +1569,40 @@ release(): Promise\<void>
| GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 | | GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 |
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 | | 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.
先完成此消息的编辑!
想要评论请 注册