js-apis-image.md 105.2 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.multimedia.image (图片处理)
X
xiaok 已提交
2

X
xu-rui-w 已提交
3 4
本模块提供图片处理效果,包括通过属性创建PixelMap、读取图像像素数据、读取区域内的图片数据等。

Z
zengyawen 已提交
5
> **说明:**
H
update  
HelloCrease 已提交
6
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
7

Z
zengyawen 已提交
8
## 导入模块
X
xiaok 已提交
9

Z
zengyawen 已提交
10
```js
Z
zengyawen 已提交
11
import image from '@ohos.multimedia.image';
X
xiaok 已提交
12 13
```

Z
zengyawen 已提交
14
## image.createPixelMap<sup>8+</sup>
X
xu-rui-w 已提交
15

16
createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
X
xiaok 已提交
17

X
xu-rui-w 已提交
18
通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过Promise返回结果。
X
xiaok 已提交
19

X
xu-rui-w 已提交
20
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
21 22 23

**参数:**

24
| 参数名  | 类型                                             | 必填 | 说明                                                             |
X
xu-rui-w 已提交
25 26
| ------- | ------------------------------------------------ | ---- | ---------------------------------------------------------------- |
| colors  | ArrayBuffer                                      | 是   | BGRA_8888格式的颜色数组。                                        |
27
| options | [InitializationOptions](#initializationoptions8) | 是   | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
X
xiaok 已提交
28 29 30

**返回值:**

X
xu-rui-w 已提交
31 32 33 34
| 类型                             | 说明                                                                    |
| -------------------------------- | ----------------------------------------------------------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 返回Pixelmap。<br>当创建的pixelmap大小超过原图大小时,返回原图pixelmap大小。|

X
xiaok 已提交
35 36 37 38

**示例:**

```js
X
xu-rui-w 已提交
39
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
40
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
41
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
F
fengzewu 已提交
42 43 44 45 46
image.createPixelMap(color, opts).then((pixelmap) => {
    console.log('Succeeded in creating pixelmap.');
}).catch(error => {
    console.log('Failed to create pixelmap.');
})
X
xiaok 已提交
47 48
```

Z
zengyawen 已提交
49
## image.createPixelMap<sup>8+</sup>
X
xiaok 已提交
50

51
createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
52

X
xu-rui-w 已提交
53
通过属性创建PixelMap,默认采用BGRA_8888格式处理数据,通过回调函数返回结果。
X
xiaok 已提交
54

X
xu-rui-w 已提交
55
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
56 57 58

**参数:**

59
| 参数名   | 类型                                             | 必填 | 说明                       |
Z
zengyawen 已提交
60
| -------- | ------------------------------------------------ | ---- | -------------------------- |
X
xu-rui-w 已提交
61
| colors   | ArrayBuffer                                      | 是   | BGRA_8888格式的颜色数组。  |
62
| options  | [InitializationOptions](#initializationoptions8) | 是   | 属性。                     |
Z
zengyawen 已提交
63
| callback | AsyncCallback\<[PixelMap](#pixelmap7)>           | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
64 65 66 67

**示例:**

```js
X
xu-rui-w 已提交
68
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
69
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
70
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
71 72 73 74 75 76 77
image.createPixelMap(color, opts, (error, pixelmap) => {
    if(error) {
        console.log('Failed to create pixelmap.');
    } else {
        console.log('Succeeded in creating pixelmap.');
    }
})
X
xiaok 已提交
78 79
```

Z
zengyawen 已提交
80
## PixelMap<sup>7+</sup>
Z
zengyawen 已提交
81

82
图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过createPixelMap创建一个PixelMap实例。目前pixelmap序列化大小最大128MB,超过会送显失败。大小计算方式为(宽\*\*每像素占用字节数)。
Z
zengyawen 已提交
83 84 85

 ### 属性

X
xu-rui-w 已提交
86
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
87

X
xu-rui-w 已提交
88 89 90
| 名称       | 类型    | 可读 | 可写 | 说明                       |
| ---------- | ------- | ---- | ---- | -------------------------- |
| isEditable | boolean | 是   | 否   | 设定是否图像像素可被编辑。 |
Z
zengyawen 已提交
91

Z
zengyawen 已提交
92
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
93

Z
zengyawen 已提交
94
readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
X
xiaok 已提交
95

X
xu-rui-w 已提交
96
读取图像像素数据,结果写入ArrayBuffer里,使用Promise形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。
X
xiaok 已提交
97

X
xu-rui-w 已提交
98
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
99 100 101

**参数:**

X
xu-rui-w 已提交
102 103 104
| 参数名 | 类型        | 必填 | 说明                                                                                                  |
| ------ | ----------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst    | ArrayBuffer | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由getPixelBytesNumber接口获取。 |
X
xiaok 已提交
105 106 107

**返回值:**

Z
zengyawen 已提交
108
| 类型           | 说明                                            |
X
xu-rui-w 已提交
109
| -------------- | ----------------------------------------------- |
Z
zengyawen 已提交
110
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
111 112 113 114

**示例:**

```js
X
xu-rui-w 已提交
115
const readBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
116 117
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
    console.log('Succeeded in reading image pixel data.');  //符合条件则进入 
X
xu-rui-w 已提交
118
}).catch(error => {
X
xu-rui-w 已提交
119
    console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
120
})
X
xiaok 已提交
121 122
```

Z
zengyawen 已提交
123
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
124

Z
zengyawen 已提交
125
readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
X
xiaok 已提交
126

X
xu-rui-w 已提交
127
读取图像像素数据,结果写入ArrayBuffer里,使用callback形式返回。指定BGRA_8888格式创建pixelmap,读取的像素数据与原数据保持一致。
X
xiaok 已提交
128

X
xu-rui-w 已提交
129
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
130 131 132

**参数:**

X
xu-rui-w 已提交
133 134 135 136
| 参数名   | 类型                 | 必填 | 说明                                                                                                  |
| -------- | -------------------- | ---- | ----------------------------------------------------------------------------------------------------- |
| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。缓冲区大小由getPixelBytesNumber接口获取。 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。                                                                        |
X
xiaok 已提交
137 138 139 140

**示例:**

```js
X
xu-rui-w 已提交
141
const readBuffer = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
142
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
X
xu-rui-w 已提交
143
    if(err) {
X
xu-rui-w 已提交
144
        console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
145
    } else {
X
xu-rui-w 已提交
146
        console.log('Succeeded in reading image pixel data.');  //符合条件则进入
X
xu-rui-w 已提交
147 148
    }
})
X
xiaok 已提交
149 150
```

Z
zengyawen 已提交
151
### readPixels<sup>7+</sup>
X
xiaok 已提交
152

Z
zengyawen 已提交
153
readPixels(area: PositionArea): Promise\<void>
X
xiaok 已提交
154

R
renhongwei 已提交
155
读取区域内的图片数据,使用Promise形式返回。
X
xiaok 已提交
156

X
xu-rui-w 已提交
157
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
158 159 160

**参数:**

Z
zengyawen 已提交
161 162 163
| 参数名 | 类型                           | 必填 | 说明                     |
| ------ | ------------------------------ | ---- | ------------------------ |
| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
X
xiaok 已提交
164 165 166

**返回值:**

Z
zengyawen 已提交
167 168 169
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取读取结果,失败时返回错误信息。 |
X
xiaok 已提交
170 171 172 173

**示例:**

```js
X
xu-rui-w 已提交
174 175 176 177 178 179
const area = {
    pixels: new ArrayBuffer(8),
    offset: 0,
    stride: 8,
    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
X
xu-rui-w 已提交
180 181
pixelmap.readPixels(area).then(() => {
    console.log('Succeeded in reading the image data in the area.'); //符合条件则进入
X
xu-rui-w 已提交
182
}).catch(error => {
X
xu-rui-w 已提交
183
    console.log('Failed to read the image data in the area.'); //不符合条件则进入
X
xu-rui-w 已提交
184
})
X
xiaok 已提交
185 186
```

Z
zengyawen 已提交
187
### readPixels<sup>7+</sup>
X
xiaok 已提交
188

Z
zengyawen 已提交
189
readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
X
xiaok 已提交
190

Z
zengyawen 已提交
191
读取区域内的图片数据,使用callback形式返回读取结果。
X
xiaok 已提交
192

X
xu-rui-w 已提交
193
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
194 195 196

**参数:**

Z
zengyawen 已提交
197 198 199 200
| 参数名   | 类型                           | 必填 | 说明                           |
| -------- | ------------------------------ | ---- | ------------------------------ |
| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
| callback | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
201 202 203 204

**示例:**

```js
X
xu-rui-w 已提交
205
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
206
let bufferArr = new Uint8Array(color);
207 208
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
X
xu-rui-w 已提交
209 210 211 212 213 214 215 216 217 218 219
    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');
        })
    }
220
})
X
xiaok 已提交
221 222
```

Z
zengyawen 已提交
223
### writePixels<sup>7+</sup>
X
xiaok 已提交
224

Z
zengyawen 已提交
225
writePixels(area: PositionArea): Promise\<void>
X
xiaok 已提交
226

227
将PixelMap写入指定区域内,使用Promise形式返回写入结果。
X
xiaok 已提交
228

X
xu-rui-w 已提交
229
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
230 231 232

**参数:** 

Z
zengyawen 已提交
233 234
| 参数名 | 类型                           | 必填 | 说明                 |
| ------ | ------------------------------ | ---- | -------------------- |
Z
zengyawen 已提交
235
| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
X
xiaok 已提交
236 237 238

**返回值:**

Z
zengyawen 已提交
239 240 241
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取写入结果,失败时返回错误信息。 |
X
xiaok 已提交
242 243 244 245

**示例:**

```js
X
xu-rui-w 已提交
246
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
247
let bufferArr = new Uint8Array(color);
248 249 250 251
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then( pixelmap => {
        if (pixelmap == undefined) {
X
xu-rui-w 已提交
252
            console.info('createPixelMap failed.');
253 254 255 256 257 258
        }
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
        }
X
xu-rui-w 已提交
259
        let bufferArr = new Uint8Array(area.pixels);
260 261 262 263 264
        for (var i = 0; i < bufferArr.length; i++) {
            bufferArr[i] = i + 1;
        }

        pixelmap.writePixels(area).then(() => {
F
fengzewu 已提交
265
		    console.info('Succeeded to write pixelmap into the specified area.');
266
        })
X
xu-rui-w 已提交
267
    }).catch(error => {
268 269
        console.log('error: ' + error);
    })
X
xiaok 已提交
270 271
```

Z
zengyawen 已提交
272
### writePixels<sup>7+</sup>
X
xiaok 已提交
273

Z
zengyawen 已提交
274
writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
X
xiaok 已提交
275

276
将PixelMap写入指定区域内,使用callback形式返回写入结果。
X
xiaok 已提交
277

X
xu-rui-w 已提交
278
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
279 280 281

**参数:** 

Z
zengyawen 已提交
282 283
| 参数名    | 类型                           | 必填 | 说明                           |
| --------- | ------------------------------ | ---- | ------------------------------ |
Z
zengyawen 已提交
284
| area      | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。           |
X
xu-rui-w 已提交
285
| callback  | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
286 287 288 289

**示例:**

```js
F
fengzewu 已提交
290 291 292 293 294 295 296 297 298
const area = { pixels: new ArrayBuffer(8),
    offset: 0,
    stride: 8,
    region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
let bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
X
xu-rui-w 已提交
299
pixelmap.writePixels(area, (error) => {
X
xu-rui-w 已提交
300
    if (error != undefined) {
X
xu-rui-w 已提交
301
		console.info('Failed to write pixelmap into the specified area.');
X
xu-rui-w 已提交
302
	} else {
F
fengzewu 已提交
303
		console.info('Succeeded to write pixelmap into the specified area.');
X
xu-rui-w 已提交
304
	}
X
xu-rui-w 已提交
305
})
X
xiaok 已提交
306 307
```

Z
zengyawen 已提交
308
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
309

Z
zengyawen 已提交
310
writeBufferToPixels(src: ArrayBuffer): Promise\<void>
X
xiaok 已提交
311

312
读取缓冲区中的图片数据,结果写入PixelMap中,使用Promise形式返回。
X
xiaok 已提交
313

X
xu-rui-w 已提交
314
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
315 316 317

**参数:**

Z
zengyawen 已提交
318 319 320
| 参数名 | 类型        | 必填 | 说明           |
| ------ | ----------- | ---- | -------------- |
| src    | ArrayBuffer | 是   | 图像像素数据。 |
X
xiaok 已提交
321 322 323

**返回值:**

Z
zengyawen 已提交
324 325 326
| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
327 328 329 330

**示例:**

```js
X
xu-rui-w 已提交
331
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
332
let bufferArr = new Uint8Array(color);
F
fengzewu 已提交
333 334 335 336
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color).then(() => {
X
xiaok 已提交
337 338 339
    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.");
X
xu-rui-w 已提交
340
})
X
xiaok 已提交
341 342
```

Z
zengyawen 已提交
343
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
344

Z
zengyawen 已提交
345
writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
X
xiaok 已提交
346

347
读取缓冲区中的图片数据,结果写入PixelMap中,使用callback形式返回。
X
xiaok 已提交
348

X
xu-rui-w 已提交
349
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
350 351 352

**参数:**

Z
zengyawen 已提交
353 354 355 356
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| src      | ArrayBuffer          | 是   | 图像像素数据。                 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
357 358 359 360

**示例:**

```js
X
xu-rui-w 已提交
361
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
362
let bufferArr = new Uint8Array(color);
F
fengzewu 已提交
363 364 365 366
for (var i = 0; i < bufferArr.length; i++) {
    bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color, function(err) {
X
xiaok 已提交
367 368 369
    if (err) {
        console.error("Failed to write data from a buffer to a PixelMap.");
        return;
X
xu-rui-w 已提交
370 371 372
    } else {
		console.log("Succeeded in writing data from a buffer to a PixelMap.");
	}
X
xiaok 已提交
373 374 375
});
```

Z
zengyawen 已提交
376
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
377

Z
zengyawen 已提交
378
getImageInfo(): Promise\<ImageInfo>
X
xiaok 已提交
379 380 381

获取图像像素信息,使用Promise形式返回获取的图像像素信息。

X
xu-rui-w 已提交
382
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
383 384 385

**返回值:**

Z
zengyawen 已提交
386 387 388
| 类型                              | 说明                                                        |
| --------------------------------- | ----------------------------------------------------------- |
| Promise\<[ImageInfo](#imageinfo)> | Promise实例,用于异步获取图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
389 390 391 392

**示例:**

```js
X
xu-rui-w 已提交
393
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407
let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
image.createPixelMap(color, opts).then(pixelmap => {
    if (pixelmap == undefined) {
        console.error("Failed to obtain the image pixel map information.");
    }
    pixelmap.getImageInfo().then(imageInfo => {
        if (imageInfo == undefined) {
            console.error("Failed to obtain the image pixel map information.");
        }
        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
            console.log("Succeeded in obtaining the image pixel map information.");
        }
    })
})
X
xiaok 已提交
408 409
```

Z
zengyawen 已提交
410
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
411

Z
zengyawen 已提交
412
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
413 414 415

获取图像像素信息,使用callback形式返回获取的图像像素信息。

X
xu-rui-w 已提交
416
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
417 418 419

**参数:**

Z
zengyawen 已提交
420 421 422
| 参数名   | 类型                                    | 必填 | 说明                                                         |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 获取图像像素信息回调,异步返回图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
423 424 425 426

**示例:**

```js
X
xu-rui-w 已提交
427
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
    if (pixelmap == undefined) {
        console.error("Failed to obtain the image pixel map information.");
    }
    pixelmap.getImageInfo((err, imageInfo) => {
        if (imageInfo == undefined) {
            console.error("Failed to obtain the image pixel map information.");
        }
        if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
            console.log("Succeeded in obtaining the image pixel map information.");
        }
    })
X
xu-rui-w 已提交
441
})
X
xiaok 已提交
442 443
```

Z
zengyawen 已提交
444
### getBytesNumberPerRow<sup>7+</sup>
X
xiaok 已提交
445

Z
zengyawen 已提交
446
getBytesNumberPerRow(): number
X
xiaok 已提交
447 448 449

获取图像像素每行字节数。

X
xu-rui-w 已提交
450
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
451 452 453

**返回值:**

Z
zengyawen 已提交
454 455 456
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的行字节数。 |
X
xiaok 已提交
457 458 459 460

**示例:**

```js
X
xu-rui-w 已提交
461
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
462
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
463
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
464
image.createPixelMap(color, opts, (err,pixelmap) => {
X
xu-rui-w 已提交
465 466
    let rowCount = pixelmap.getBytesNumberPerRow();
})
X
xiaok 已提交
467 468
```

Z
zengyawen 已提交
469
### getPixelBytesNumber<sup>7+</sup>
X
xiaok 已提交
470

Z
zengyawen 已提交
471
getPixelBytesNumber(): number
X
xiaok 已提交
472 473 474

获取图像像素的总字节数。

X
xu-rui-w 已提交
475
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
476 477 478

**返回值:**

Z
zengyawen 已提交
479 480 481
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的总字节数。 |
X
xiaok 已提交
482 483 484 485

**示例:**

```js
X
xu-rui-w 已提交
486
let pixelBytesNumber = pixelmap.getPixelBytesNumber();
X
xiaok 已提交
487 488
```

X
xu-rui-w 已提交
489 490 491 492
### getDensity<sup>9+</sup>

getDensity():number

X
xu-rui-w 已提交
493
获取当前图像像素的密度。
X
xu-rui-w 已提交
494 495 496 497 498

**系统能力:** SystemCapability.Multimedia.Image.Core

**返回值:**

X
xu-rui-w 已提交
499 500 501
| 类型   | 说明            |
| ------ | --------------- |
| number | 图像像素的密度。|
X
xu-rui-w 已提交
502 503 504 505 506 507 508 509 510 511 512

**示例:**

```js
let getDensity = pixelmap.getDensity();
```

### opacity<sup>9+</sup>

opacity(rate: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
513
通过设置透明比率来让PixelMap达到对应的透明效果,使用callback形式返回。
X
xu-rui-w 已提交
514 515 516 517 518 519 520 521 522 523 524 525 526

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| rate     | number               | 是   | 透明比率的值,取值范围:0-1。   |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
F
fengzewu 已提交
527 528 529 530 531 532 533 534 535
var rate = 0.5;
pixelmap.opacity(rate, (err) => {
	if (err) {
        console.error("Failed to set opacity.");
        return;
    } else {
        console.log("Succeeded in setting opacity.");
	}
})
X
xu-rui-w 已提交
536 537 538 539 540 541
```

### opacity<sup>9+</sup>

opacity(rate: number): Promise\<void>

X
xu-rui-w 已提交
542
通过设置透明比率来让PixelMap达到对应的透明效果,使用Promise形式返回。
X
xu-rui-w 已提交
543 544 545 546 547 548 549

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                        |
| ------ | ------ | ---- | --------------------------- |
X
xu-rui-w 已提交
550
| rate   | number | 是   | 透明比率的值,取值范围:0-1。|
X
xu-rui-w 已提交
551 552 553 554 555 556 557 558 559 560

**返回值:**

| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |

**示例:**

```js
F
fengzewu 已提交
561
async function Demo() {
F
fengzewu 已提交
562
    await pixelmap.opacity(0.5);
X
xu-rui-w 已提交
563
}
X
xu-rui-w 已提交
564 565 566 567 568 569
```

### createAlphaPixelmap<sup>9+</sup>

createAlphaPixelmap(): Promise\<PixelMap>

X
xu-rui-w 已提交
570
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用Promise形式返回。
X
xu-rui-w 已提交
571 572 573 574 575 576 577 578 579 580 581 582

**系统能力:** SystemCapability.Multimedia.Image.Core

**返回值:**

| 类型                             | 说明                        |
| -------------------------------- | --------------------------- |
| Promise\<[PixelMap](#pixelmap7)> | Promise实例,返回pixelmap。 |

**示例:**

```js
F
fengzewu 已提交
583
async function Demo() {
F
fengzewu 已提交
584 585
    await pixelmap.createAlphaPixelmap();
}   
X
xu-rui-w 已提交
586 587 588 589 590 591
```

### createAlphaPixelmap<sup>9+</sup>

createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void

X
xu-rui-w 已提交
592
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用callback形式返回。
X
xu-rui-w 已提交
593 594 595 596 597

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
598 599 600
| 参数名   | 类型                     | 必填 | 说明                     |
| -------- | ------------------------ | ---- | ------------------------ |
| callback | AsyncCallback\<PixelMap> | 是   | 获取回调,异步返回结果。 |
X
xu-rui-w 已提交
601 602 603 604

**示例:**

```js
F
fengzewu 已提交
605 606 607 608 609 610 611
pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
    if (alphaPixelMap == undefined) {
        console.info('Failed to obtain new pixel map.');
    } else {
        console.info('Succeed in obtaining new pixel map.');
    }
})
X
xu-rui-w 已提交
612 613 614 615 616 617
```

### scale<sup>9+</sup>

scale(x: number, y: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
618
根据输入的宽高对图片进行缩放,使用callback形式返回。
X
xu-rui-w 已提交
619 620 621 622 623

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
624 625 626 627 628
| 参数名   | 类型                 | 必填 | 说明                            |
| -------- | -------------------- | ---- | ------------------------------- |
| x        | number               | 是   | 宽度的缩放值,其值为输入的倍数。|
| y        | number               | 是   | 高度的缩放值,其值为输入的倍数。|
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。  |
X
xu-rui-w 已提交
629 630 631 632

**示例:**

```js
F
fengzewu 已提交
633
async function Demo() {
F
fengzewu 已提交
634
	await pixelmap.scale(2.0, 1.0);
X
xu-rui-w 已提交
635
}
X
xu-rui-w 已提交
636 637 638 639 640 641
```

### scale<sup>9+</sup>

scale(x: number, y: number): Promise\<void>

X
xu-rui-w 已提交
642
根据输入的宽高对图片进行缩放,使用Promise形式返回。
X
xu-rui-w 已提交
643 644 645 646 647

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
648 649 650 651
| 参数名 | 类型   | 必填 | 说明                            |
| ------ | ------ | ---- | ------------------------------- |
| x      | number | 是   | 宽度的缩放值,其值为输入的倍数。|
| y      | number | 是   | 高度的缩放值,其值为输入的倍数。|
X
xu-rui-w 已提交
652 653 654

**返回值:**

X
xu-rui-w 已提交
655 656 657
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
658 659 660 661

**示例:**

```js
F
fengzewu 已提交
662
async function Demo() {
F
fengzewu 已提交
663
	await pixelmap.scale(2.0, 1.0);
X
xu-rui-w 已提交
664
}
X
xu-rui-w 已提交
665 666 667 668 669 670
```

### translate<sup>9+</sup>

translate(x: number, y: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
671
根据输入的坐标对图片进行位置变换,使用callback形式返回。
X
xu-rui-w 已提交
672 673 674 675 676 677 678 679 680 681 682 683 684 685

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| x        | number               | 是   | 区域横坐标。                  |
| y        | number               | 是   | 区域纵坐标。                  |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
686
async function Demo() {
F
fengzewu 已提交
687
	await pixelmap.translate(3.0, 1.0);
X
xu-rui-w 已提交
688
}
X
xu-rui-w 已提交
689 690 691 692 693 694
```

### translate<sup>9+</sup>

translate(x: number, y: number): Promise\<void>

X
xu-rui-w 已提交
695
根据输入的坐标对图片进行位置变换,使用Promise形式返回。
X
xu-rui-w 已提交
696 697 698 699 700 701 702 703 704 705 706 707

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明        |
| ------ | ------ | ---- | ----------- |
| x      | number | 是   | 区域横坐标。|
| y      | number | 是   | 区域纵坐标。|

**返回值:**

X
xu-rui-w 已提交
708 709 710
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
711 712 713 714

**示例:**

```js
F
fengzewu 已提交
715
async function Demo() {
F
fengzewu 已提交
716
	await pixelmap.translate(3.0, 1.0);
X
xu-rui-w 已提交
717
}
X
xu-rui-w 已提交
718 719 720 721 722 723
```

### rotate<sup>9+</sup>

rotate(angle: number, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
724
根据输入的角度对图片进行旋转,使用callback形式返回。
X
xu-rui-w 已提交
725 726 727 728 729 730 731 732 733 734 735 736 737

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| angle    | number               | 是   | 图片旋转的角度。              |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
Y
yaozhupeng 已提交
738 739 740 741 742 743 744 745 746
var angle = 90.0;
pixelmap.rotate(angle, (err) => {
	if (err) {
        console.error("Failed to set rotation.");
        return;
    } else {
        console.log("Succeeded in setting rotation.");
	}
})
X
xu-rui-w 已提交
747 748 749 750 751 752
```

### rotate<sup>9+</sup>

rotate(angle: number): Promise\<void>

X
xu-rui-w 已提交
753
根据输入的角度对图片进行旋转,使用Promise形式返回。
X
xu-rui-w 已提交
754 755 756 757 758 759 760 761 762 763 764

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                          |
| ------ | ------ | ---- | ----------------------------- |
| angle  | number | 是   | 图片旋转的角度。              |

**返回值:**

X
xu-rui-w 已提交
765 766 767
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
768 769 770 771

**示例:**

```js
F
fengzewu 已提交
772
async function Demo() {
F
fengzewu 已提交
773
	await pixelmap.rotate(90.0);
X
xu-rui-w 已提交
774
}
X
xu-rui-w 已提交
775 776 777 778 779 780
```

### flip<sup>9+</sup>

flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
781
根据输入的条件对图片进行翻转,使用callback形式返回。
X
xu-rui-w 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名     | 类型                 | 必填 | 说明                          |
| ---------- | -------------------- | ---- | ----------------------------- |
| horizontal | boolean              | 是   | 水平翻转。                    |
| vertical   | boolean              | 是   | 垂直翻转。                    |
| callback   | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
796
async function Demo() {
F
fengzewu 已提交
797
	await pixelmap.flip(false, true);
X
xu-rui-w 已提交
798
}
X
xu-rui-w 已提交
799 800 801 802 803 804
```

### flip<sup>9+</sup>

flip(horizontal: boolean, vertical: boolean): Promise\<void>

X
xu-rui-w 已提交
805
根据输入的条件对图片进行翻转,使用Promise形式返回。
X
xu-rui-w 已提交
806 807 808 809 810 811 812 813 814 815 816 817

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名     | 类型    | 必填 | 说明      |
| ---------- | ------- | ---- | --------- |
| horizontal | boolean | 是   | 水平翻转。|
| vertical   | boolean | 是   | 垂直翻转。|

**返回值:**

X
xu-rui-w 已提交
818 819 820
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
821 822 823 824

**示例:**

```js
F
fengzewu 已提交
825
async function Demo() {
F
fengzewu 已提交
826
	await pixelmap.flip(false, true);
X
xu-rui-w 已提交
827
}
X
xu-rui-w 已提交
828 829 830 831 832 833
```

### crop<sup>9+</sup>

crop(region: Region, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
834
根据输入的尺寸对图片进行裁剪,使用callback形式返回。
X
xu-rui-w 已提交
835 836 837 838 839 840 841

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
X
xu-rui-w 已提交
842
| region   | [Region](#region7)   | 是   | 裁剪的尺寸。                  |
X
xu-rui-w 已提交
843 844 845 846 847
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
F
fengzewu 已提交
848
async function Demo() {
F
fengzewu 已提交
849
	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
850
}
X
xu-rui-w 已提交
851 852 853 854 855 856
```

### crop<sup>9+</sup>

crop(region: Region): Promise\<void>

X
xu-rui-w 已提交
857
根据输入的尺寸对图片进行裁剪,使用Promise形式返回。
X
xu-rui-w 已提交
858 859 860 861 862

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

X
xu-rui-w 已提交
863 864 865
| 参数名 | 类型               | 必填 | 说明        |
| ------ | ------------------ | ---- | ----------- |
| region | [Region](#region7) | 是   | 裁剪的尺寸。|
X
xu-rui-w 已提交
866 867 868

**返回值:**

X
xu-rui-w 已提交
869 870 871
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
872 873 874 875

**示例:**

```js
F
fengzewu 已提交
876
async function Demo() {
F
fengzewu 已提交
877
	await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
878
}
X
xu-rui-w 已提交
879 880
```

F
fengzewu 已提交
881 882 883 884 885 886 887 888 889 890 891 892 893 894
### getColorSpace<sup>10+</sup>

getColorSpace(): colorSpaceManager.ColorSpaceManager

获取图像广色域信息。

**系统能力:** SystemCapability.Multimedia.Image.Core

**返回值:**

| 类型                                | 说明             |
| ----------------------------------- | ---------------- |
| [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | 图像广色域信息。 |

黄开兴 已提交
895 896 897 898 899 900 901 902 903 904
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980101| If the image data abnormal              |
| 62980103| If the image data unsupport              |
| 62980115| If the image parameter invalid             |

F
fengzewu 已提交
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
**示例:**

```js
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
async function Demo() {
    let csm = pixelmap.getColorSpace();
}
```

### setColorSpace<sup>10+</sup>

setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void

设置图像广色域信息。

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名     | 类型                                | 必填 | 说明            |
| ---------- | ----------------------------------- | ---- | --------------- |
| colorSpace | [colorSpaceManager.ColorSpaceManager](js-apis-colorSpaceManager.md#colorspacemanager) | 是   | 图像广色域信息。|

黄开兴 已提交
928 929 930 931 932 933 934 935 936
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980111| If the operation invalid              |
| 62980115| If the image parameter invalid             |

黄开兴 已提交
937 938
**示例:**

F
fengzewu 已提交
939 940 941 942 943 944 945 946
```js
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
async function Demo() {
    var csm = colorSpaceManager.create(colorSpaceName);
    pixelmap.setColorSpace(csm);
}
```

Z
zengyueyang 已提交
947 948 949 950 951 952 953 954 955 956 957 958 959 960
### marshalling<sup>10+</sup>

marshalling(sequence: rpc.MessageSequence): void

将PixelMap序列化后写入MessageSequence。

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名                 | 类型                                                  | 必填 | 说明                                     |
| ---------------------- | ------------------------------------------------------ | ---- | ---------------------------------------- |
| sequence               | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9)  | 是   | 新创建的MessageSequence。                 |

961 962
**错误码:**

黄开兴 已提交
963
以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)
964 965 966 967 968 969

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980115 | If the input parameter invalid              |
| 62980097 | If the ipc error              |

Z
zengyueyang 已提交
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
**示例:**

```js
import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc'
class MySequence {
    pixel_map;
    constructor(pixelmap) {
        this.pixel_map = pixelmap;
    }
    marshalling(messageSequence) {
        this.pixel_map.marshalling(messageSequence);
        return true;
    }
    async unmarshalling(messageSequence) {
        await image.unmarshalling(messageSequence).then(async (pixelMap) => {
986
            this.pixel_map = pixelMap;
Z
zengyueyang 已提交
987 988 989 990 991
        })
        return true;
    }
}
async function Demo() {
992
    let parcelable = new MySequence(pixelmap);
Z
zengyueyang 已提交
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
    let data = rpc.MessageSequence.create();
    data.writeParcelable(parcelable);
}
```

### unmarshalling<sup>10+</sup>

unmarshalling(sequence: rpc.MessageSequence): Promise\<PixelMap>

从MessageSequence中获取PixelMap。

**系统能力:** SystemCapability.Multimedia.Image.Core

**参数:**

| 参数名                 | 类型                                                  | 必填 | 说明                                     |
| ---------------------- | ----------------------------------------------------- | ---- | ---------------------------------------- |
| sequence               | [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) | 是   | 保存有PixelMap信息的MessageSequence。      |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 异步返回Promise对象。 |

1018 1019
**错误码:**

黄开兴 已提交
1020
以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)
1021 1022 1023 1024 1025 1026

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980115 | If the input parameter invalid              |
| 62980097 | If the ipc error              |

Z
zengyueyang 已提交
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
**示例:**

```js
import image from '@ohos.multimedia.image'
import rpc from '@ohos.rpc'
class MySequence {
    pixel_map;
    constructor(pixelmap) {
        this.pixel_map = pixelmap;
    }
    marshalling(messageSequence) {
        this.pixel_map.marshalling(messageSequence);
        return true;
    }
    async unmarshalling(messageSequence) {
        await image.unmarshalling(messageSequence).then(async (pixelMap) => {
1043
            this.pixel_map = pixelMap;
Z
zengyueyang 已提交
1044 1045 1046 1047 1048 1049 1050
        })
        return true;
    }
}
async function Demo() {
    let pixel_map = undefined;
    let ret = new MySequence(pixel_map);
1051
    let data = rpc.MessageSequence.create();
Z
zengyueyang 已提交
1052 1053 1054 1055
    await data.readParcelable(ret);
}
```

Z
zengyawen 已提交
1056
### release<sup>7+</sup>
X
xiaok 已提交
1057

Z
zengyawen 已提交
1058
release():Promise\<void>
X
xiaok 已提交
1059

1060
释放PixelMap对象,使用Promise形式返回释放结果。
X
xiaok 已提交
1061

X
xu-rui-w 已提交
1062
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
1063

Z
zengyawen 已提交
1064
**返回值:**
X
xiaok 已提交
1065

X
xu-rui-w 已提交
1066 1067 1068
| 类型           | 说明                            |
| -------------- | ------------------------------- |
| Promise\<void> | Promise实例,异步返回释放结果。 |
X
xiaok 已提交
1069 1070 1071 1072

**示例:**

```js
F
fengzewu 已提交
1073 1074 1075 1076
pixelmap.release().then(() => {
	console.log('Succeeded in releasing pixelmap object.');
}).catch(error => {
	console.log('Failed to release pixelmap object.');
X
xu-rui-w 已提交
1077
})
X
xiaok 已提交
1078 1079
```

Z
zengyawen 已提交
1080
### release<sup>7+</sup>
X
xiaok 已提交
1081

Z
zengyawen 已提交
1082
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
1083

1084
释放PixelMap对象,使用callback形式返回释放结果。
X
xiaok 已提交
1085

X
xu-rui-w 已提交
1086
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
1087 1088 1089

**参数:**

1090
| 参数名   | 类型                 | 必填 | 说明               |
Z
zengyawen 已提交
1091 1092
| -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | 是   | 异步返回释放结果。 |
X
xiaok 已提交
1093 1094 1095 1096

**示例:**

```js
F
fengzewu 已提交
1097 1098
pixelmap.release(() => {
    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
1099
})
X
xiaok 已提交
1100 1101
```

Z
zengyawen 已提交
1102
## image.createImageSource
X
xiaok 已提交
1103

Z
zengyawen 已提交
1104
createImageSource(uri: string): ImageSource
X
xiaok 已提交
1105

Z
zengyawen 已提交
1106
通过传入的uri创建图片源实例。
X
xiaok 已提交
1107

X
xu-rui-w 已提交
1108
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1109 1110 1111

**参数:**

Z
zengyawen 已提交
1112 1113
| 参数名 | 类型   | 必填 | 说明                               |
| ------ | ------ | ---- | ---------------------------------- |
1114
| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW [SVG<sup>10+</sup>](#svg标签说明)。 |
X
xiaok 已提交
1115 1116 1117

**返回值:**

1118 1119 1120
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
1121 1122 1123 1124

**示例:**

```js
F
fengzewu 已提交
1125 1126
//Stage模型
const context = getContext(this);
Z
zhangqiang183 已提交
1127
const path = context.cacheDir + "/test.jpg";
F
fengzewu 已提交
1128 1129 1130 1131 1132 1133 1134 1135 1136
const imageSourceApi = image.createImageSource(path);
```

```js
//FA模型
import featureAbility from '@ohos.ability.featureAbility';

const context = featureAbility.getContext();
const path = context.getCacheDir() + "/test.jpg";
Z
zhang-xiaobo1997 已提交
1137
const imageSourceApi = image.createImageSource(path);
X
xiaok 已提交
1138 1139
```

X
xu-rui-w 已提交
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
## image.createImageSource<sup>9+</sup>

createImageSource(uri: string, options: SourceOptions): ImageSource

通过传入的uri创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
1152
| uri     | string                          | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW [SVG<sup>10+</sup>](#svg标签说明)。 |
1153
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1164 1165
var sourceOptions = { sourceDensity: 120 };
let imageSource = image.createImageSource('test.png', sourceOptions);
X
xu-rui-w 已提交
1166 1167
```

Z
zengyawen 已提交
1168
## image.createImageSource<sup>7+</sup>
X
xiaok 已提交
1169

Z
zengyawen 已提交
1170
createImageSource(fd: number): ImageSource
X
xiaok 已提交
1171

Z
zengyawen 已提交
1172
通过传入文件描述符来创建图片源实例。
X
xiaok 已提交
1173

X
xu-rui-w 已提交
1174
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1175 1176 1177

**参数:**

X
xu-rui-w 已提交
1178 1179 1180
| 参数名 | 类型   | 必填 | 说明          |
| ------ | ------ | ---- | ------------- |
| fd     | number | 是   | 文件描述符fd。|
X
xiaok 已提交
1181 1182 1183

**返回值:**

1184 1185 1186
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
1187 1188 1189 1190

**示例:**

```js
X
xu-rui-w 已提交
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
const imageSourceApi = image.createImageSource(0);
```

## image.createImageSource<sup>9+</sup>

createImageSource(fd: number, options: SourceOptions): ImageSource

通过传入文件描述符来创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
| fd      | number                          | 是   | 文件描述符fd。                      |
1207
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
F
fengzewu 已提交
1218 1219
var sourceOptions = { sourceDensity: 120 };
const imageSourceApi = image.createImageSource(0, sourceOptions);
X
xu-rui-w 已提交
1220 1221 1222
```

## image.createImageSource<sup>9+</sup>
X
xiaok 已提交
1223

X
xu-rui-w 已提交
1224
createImageSource(buf: ArrayBuffer): ImageSource
X
xiaok 已提交
1225

X
xu-rui-w 已提交
1226
通过缓冲区创建图片源实例。
X
xiaok 已提交
1227

X
xu-rui-w 已提交
1228
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1229 1230 1231

**参数:**

X
xu-rui-w 已提交
1232 1233 1234
| 参数名 | 类型        | 必填 | 说明             |
| ------ | ----------- | ---- | ---------------- |
| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
X
xiaok 已提交
1235 1236 1237 1238

**示例:**

```js
X
xu-rui-w 已提交
1239
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
X
xu-rui-w 已提交
1240
const imageSourceApi = image.createImageSource(buf);
X
xiaok 已提交
1241 1242
```

X
xu-rui-w 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
## image.createImageSource<sup>9+</sup>

createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource

通过缓冲区创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名 | 类型                             | 必填 | 说明                                 |
| ------ | -------------------------------- | ---- | ------------------------------------ |
| buf    | ArrayBuffer                      | 是   | 图像缓冲区数组。                     |
1256
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266

**返回值:**

| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1267 1268
const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);
X
xu-rui-w 已提交
1269 1270
```

1271
## image.CreateIncrementalSource<sup>9+</sup>
X
xu-rui-w 已提交
1272

1273
CreateIncrementalSource(buf: ArrayBuffer): ImageSource
X
xu-rui-w 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293

通过缓冲区以增量的方式创建图片源实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名  | 类型        | 必填 | 说明      |
| ------- | ------------| ---- | ----------|
| buf     | ArrayBuffer | 是   | 增量数据。|

**返回值:**

| 类型                        | 说明                              |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1294
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1295
const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
X
xu-rui-w 已提交
1296 1297
```

1298
## image.CreateIncrementalSource<sup>9+</sup>
X
xu-rui-w 已提交
1299

1300
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
X
xu-rui-w 已提交
1301

X
xu-rui-w 已提交
1302
通过缓冲区以增量的方式创建图片源实例。
X
xu-rui-w 已提交
1303

X
xu-rui-w 已提交
1304
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1305 1306 1307 1308 1309

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                 |
| ------- | ------------------------------- | ---- | ------------------------------------ |
X
xu-rui-w 已提交
1310
| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
1311
| options | [SourceOptions](#sourceoptions9) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321

**返回值:**

| 类型                        | 说明                              |
| --------------------------- | --------------------------------- |
| [ImageSource](#imagesource) | 返回图片源,失败时返回undefined。 |

**示例:**

```js
X
xu-rui-w 已提交
1322
const buf = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
1323
const imageSourceIncrementalSApi = image.CreateIncrementalSource(buf);
X
xiaok 已提交
1324 1325
```

Z
zengyawen 已提交
1326
## ImageSource
X
xiaok 已提交
1327

Z
zengyawen 已提交
1328 1329 1330 1331
图片源类,用于获取图片相关信息。在调用ImageSource的方法前,需要先通过createImageSource构建一个ImageSource实例。

### 属性

X
xu-rui-w 已提交
1332
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zhang-xiaobo1997 已提交
1333

Z
zengyawen 已提交
1334 1335
| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
X
xu-rui-w 已提交
1336
| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,bmp,gif,webp,RAW。 |
Z
zengyawen 已提交
1337 1338 1339 1340

### getImageInfo

getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1341 1342 1343

获取指定序号的图片信息,使用callback形式返回图片信息。

X
xu-rui-w 已提交
1344
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1345 1346 1347

**参数:**

Z
zengyawen 已提交
1348 1349 1350 1351
| 参数名   | 类型                                   | 必填 | 说明                                     |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| index    | number                                 | 是   | 创建图片源时的序号。                     |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1352 1353 1354 1355

**示例:**

```js
X
xu-rui-w 已提交
1356 1357 1358 1359 1360 1361 1362
imageSourceApi.getImageInfo(0,(error, imageInfo) => { 
    if(error) {
        console.log('getImageInfo failed.');
    } else {
        console.log('getImageInfo succeeded.');
    }
})
X
xiaok 已提交
1363 1364
```

Z
zengyawen 已提交
1365
### getImageInfo
X
xiaok 已提交
1366

Z
zengyawen 已提交
1367
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1368

Z
zengyawen 已提交
1369
获取图片信息,使用callback形式返回图片信息。
X
xiaok 已提交
1370

X
xu-rui-w 已提交
1371
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1372 1373 1374

**参数:**

1375
| 参数名   | 类型                                   | 必填 | 说明                                     |
X
xiaok 已提交
1376
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
Z
zengyawen 已提交
1377
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1378 1379 1380 1381

**示例:**

```js
X
xu-rui-w 已提交
1382
imageSourceApi.getImageInfo(imageInfo => { 
X
xu-rui-w 已提交
1383
    console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1384
})
X
xiaok 已提交
1385 1386
```

Z
zengyawen 已提交
1387
### getImageInfo
X
xiaok 已提交
1388

Z
zengyawen 已提交
1389
getImageInfo(index?: number): Promise\<ImageInfo>
X
xiaok 已提交
1390 1391 1392

获取图片信息,使用Promise形式返回图片信息。

X
xu-rui-w 已提交
1393
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1394 1395 1396

**参数:**

1397
| 参数名| 类型   | 必填 | 说明                                  |
Z
zengyawen 已提交
1398 1399
| ----- | ------ | ---- | ------------------------------------- |
| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
X
xiaok 已提交
1400 1401 1402

**返回值:**

Z
zengyawen 已提交
1403 1404 1405
| 类型                             | 说明                   |
| -------------------------------- | ---------------------- |
| Promise<[ImageInfo](#imageinfo)> | 返回获取到的图片信息。 |
X
xiaok 已提交
1406 1407 1408 1409 1410

**示例:**

```js
imageSourceApi.getImageInfo(0)
X
xu-rui-w 已提交
1411
    .then(imageInfo => {
X
xu-rui-w 已提交
1412
		console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1413
	}).catch(error => {
X
xu-rui-w 已提交
1414
		console.log('Failed to obtain the image information.');
X
xu-rui-w 已提交
1415
	})
X
xiaok 已提交
1416 1417
```

Z
zengyawen 已提交
1418
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1419

Z
zengyawen 已提交
1420
getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string>
X
xiaok 已提交
1421

Z
zengyawen 已提交
1422
获取图片中给定索引处图像的指定属性键的值,用Promise形式返回结果。
X
xiaok 已提交
1423

X
xu-rui-w 已提交
1424
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1425 1426 1427

 **参数:**

1428
| 参数名  | 类型                                                 | 必填 | 说明                                 |
Z
zengyawen 已提交
1429 1430 1431
| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
| key     | string                                               | 是   | 图片属性名。                         |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xiaok 已提交
1432 1433 1434

**返回值:**

X
xu-rui-w 已提交
1435 1436
| 类型             | 说明                                                              |
| ---------------- | ----------------------------------------------------------------- |
Z
zengyawen 已提交
1437
| Promise\<string> | Promise实例,用于异步获取图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1438 1439 1440 1441

**示例:**

```js
1442
imageSourceApi.getImageProperty("BitsPerSample")
X
xu-rui-w 已提交
1443
    .then(data => {
X
xu-rui-w 已提交
1444
		console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1445
	})
X
xiaok 已提交
1446 1447
```

Z
zengyawen 已提交
1448
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1449

Z
zengyawen 已提交
1450
getImageProperty(key:string, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1451

Z
zengyawen 已提交
1452
获取图片中给定索引处图像的指定属性键的值,用callback形式返回结果。
X
xiaok 已提交
1453

X
xu-rui-w 已提交
1454
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1455 1456 1457

 **参数:**

Z
zengyawen 已提交
1458 1459 1460 1461
| 参数名   | 类型                   | 必填 | 说明                                                         |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| key      | string                 | 是   | 图片属性名。                                                 |
| callback | AsyncCallback\<string> | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1462 1463 1464 1465

**示例:**

```js
X
xu-rui-w 已提交
1466 1467
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { 
    if(error) {
X
xu-rui-w 已提交
1468
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1469
    } else {
X
xu-rui-w 已提交
1470
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1471 1472
    }
})
X
xiaok 已提交
1473 1474
```

Z
zengyawen 已提交
1475
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1476

Z
zengyawen 已提交
1477
getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1478 1479 1480

获取图片指定属性键的值,callback形式返回结果。

X
xu-rui-w 已提交
1481
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1482 1483 1484

**参数:**

X
xu-rui-w 已提交
1485 1486 1487 1488 1489
| 参数名   | 类型                                                 | 必填 | 说明                                                          |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
| key      | string                                               | 是   | 图片属性名。                                                  |
| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | 是   | 图片属性,包括图片序号与默认属性值。                          |
| callback | AsyncCallback\<string>                               | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。|
X
xiaok 已提交
1490 1491 1492 1493

**示例:**

```js
F
fengzewu 已提交
1494
let property = { index: 0, defaultValue: '9999' }
X
xu-rui-w 已提交
1495
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { 
X
xu-rui-w 已提交
1496
    if(error) {
X
xu-rui-w 已提交
1497
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1498
    } else {
X
xu-rui-w 已提交
1499
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1500 1501
    }
})
X
xiaok 已提交
1502 1503
```

X
xu-rui-w 已提交
1504
### modifyImageProperty<sup>9+</sup>
X
xu-rui-w 已提交
1505

X
xu-rui-w 已提交
1506
modifyImageProperty(key: string, value: string): Promise\<void>
X
xu-rui-w 已提交
1507

X
xu-rui-w 已提交
1508
通过指定的键修改图片属性的值,使用Promise形式返回结果。
X
xu-rui-w 已提交
1509

X
xu-rui-w 已提交
1510
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520

**参数:**

| 参数名  | 类型   | 必填 | 说明         |
| ------- | ------ | ---- | ------------ |
| key     | string | 是   | 图片属性名。 |
| value   | string | 是   | 属性值。     |

**返回值:**

X
xu-rui-w 已提交
1521 1522 1523
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
1524 1525 1526 1527

**示例:**

```js
F
fengzewu 已提交
1528 1529 1530 1531
imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
    const w = imageSourceApi.getImageProperty("ImageWidth")
    console.info('w', w);
})
X
xu-rui-w 已提交
1532 1533
```

X
xu-rui-w 已提交
1534
### modifyImageProperty<sup>9+</sup>
X
xu-rui-w 已提交
1535

X
xu-rui-w 已提交
1536
modifyImageProperty(key: string, value: string, callback: AsyncCallback\<void>): void
X
xu-rui-w 已提交
1537

X
xu-rui-w 已提交
1538
通过指定的键修改图片属性的值,callback形式返回结果。
X
xu-rui-w 已提交
1539

X
xu-rui-w 已提交
1540
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1541 1542 1543 1544 1545 1546 1547

**参数:**

| 参数名   | 类型                | 必填 | 说明                           |
| -------- | ------------------- | ---- | ------------------------------ |
| key      | string              | 是   | 图片属性名。                   |
| value    | string              | 是   | 属性值。                       |
1548
| callback | AsyncCallback\<void> | 是   | 修改属性值,callback返回结果。 |
X
xu-rui-w 已提交
1549 1550 1551 1552

**示例:**

```js
X
xu-rui-w 已提交
1553
imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
X
xu-rui-w 已提交
1554 1555
```

X
xu-rui-w 已提交
1556
### updateData<sup>9+</sup>
X
xu-rui-w 已提交
1557

X
xu-rui-w 已提交
1558
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise\<void>
X
xu-rui-w 已提交
1559

X
xu-rui-w 已提交
1560
更新增量数据,使用Promise形式返回结果。
X
xu-rui-w 已提交
1561

X
xu-rui-w 已提交
1562
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1563 1564 1565

**参数:**

1566
| 参数名     | 类型        | 必填 | 说明         |
X
xu-rui-w 已提交
1567 1568 1569
| ---------- | ----------- | ---- | ------------ |
| buf        | ArrayBuffer | 是   | 增量数据。   |
| isFinished | boolean     | 是   | 是否更新完。 |
1570 1571
| value      | number      | 是   | 偏移量。     |
| length     | number      | 是   | 数组长。     |
X
xu-rui-w 已提交
1572 1573 1574

**返回值:**

X
xu-rui-w 已提交
1575 1576 1577
| 类型           | 说明                       |
| -------------- | -------------------------- |
| Promise\<void> | Promise实例,异步返回结果。|
X
xu-rui-w 已提交
1578 1579 1580 1581 1582

**示例:**

```js
const array = new ArrayBuffer(100);
F
fengzewu 已提交
1583 1584 1585
imageSourceApi.updateData(array, false, 0, 10).then(data => {
    console.info('Succeeded in updating data.');
})
X
xu-rui-w 已提交
1586 1587 1588
```


X
xu-rui-w 已提交
1589
### updateData<sup>9+</sup>
X
xu-rui-w 已提交
1590

X
xu-rui-w 已提交
1591
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback\<void>): void
X
xu-rui-w 已提交
1592

X
xu-rui-w 已提交
1593
更新增量数据,callback形式返回结果。
X
xu-rui-w 已提交
1594

X
xu-rui-w 已提交
1595
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1596 1597 1598

**参数:**

1599
| 参数名     | 类型                | 必填 | 说明                 |
X
xu-rui-w 已提交
1600 1601 1602
| ---------- | ------------------- | ---- | -------------------- |
| buf        | ArrayBuffer         | 是   | 增量数据。           |
| isFinished | boolean             | 是   | 是否更新完。         |
1603 1604
| value      | number              | 是   | 偏移量。             |
| length     | number              | 是   | 数组长。             |
1605
| callback   | AsyncCallback\<void> | 是   | 回调表示成功或失败。 |
X
xu-rui-w 已提交
1606 1607 1608 1609 1610

**示例:**

```js
const array = new ArrayBuffer(100);
F
fengzewu 已提交
1611 1612 1613 1614 1615
imageSourceApi.updateData(array, false, 0, 10,(error,data )=> {
    if(data !== undefined){
        console.info('Succeeded in updating data.');     
    }
})
X
xu-rui-w 已提交
1616 1617
```

Z
zengyawen 已提交
1618
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1619

Z
zengyawen 已提交
1620
createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
X
xiaok 已提交
1621

1622
通过图片解码参数创建PixelMap对象。
X
xiaok 已提交
1623

X
xu-rui-w 已提交
1624
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1625 1626 1627

**参数:**

1628
| 参数名  | 类型                                 | 必填 | 说明       |
Z
zengyawen 已提交
1629 1630 1631 1632 1633 1634 1635 1636
| ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 异步返回Promise对象。 |
X
xiaok 已提交
1637 1638 1639 1640

**示例:**

```js
X
xu-rui-w 已提交
1641
imageSourceApi.createPixelMap().then(pixelmap => {
X
xu-rui-w 已提交
1642
    console.log('Succeeded in creating pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1643
}).catch(error => {
X
xu-rui-w 已提交
1644
    console.log('Failed to create pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1645
})
X
xiaok 已提交
1646 1647
```

Z
zengyawen 已提交
1648
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1649

Z
zengyawen 已提交
1650
createPixelMap(callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
1651

1652
通过默认参数创建PixelMap对象,使用callback形式返回结果。
X
xiaok 已提交
1653

X
xu-rui-w 已提交
1654
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1655 1656 1657

**参数:**

1658
| 参数名     | 类型                                  | 必填 | 说明                       |
Z
zengyawen 已提交
1659 1660
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1661 1662 1663 1664

**示例:**

```js
X
xu-rui-w 已提交
1665
imageSourceApi.createPixelMap((err, pixelmap) => {
R
renhongwei 已提交
1666 1667
    console.info('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1668 1669
```

Z
zengyawen 已提交
1670
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1671

Z
zengyawen 已提交
1672
createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): void
X
xiaok 已提交
1673

Z
zengyawen 已提交
1674
通过图片解码参数创建PixelMap对象。
X
xiaok 已提交
1675

X
xu-rui-w 已提交
1676
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1677 1678 1679

**参数:**

1680
| 参数名   | 类型                                  | 必填 | 说明                       |
Z
zengyawen 已提交
1681
| -------- | ------------------------------------- | ---- | -------------------------- |
1682
| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
Z
zengyawen 已提交
1683
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1684 1685 1686 1687

**示例:**

```js
F
fengzewu 已提交
1688 1689 1690 1691 1692 1693 1694 1695 1696
let decodingOptions = {
    sampleSize: 1,
    editable: true,
    desiredSize: { width: 1, height: 2 },
    rotate: 10,
    desiredPixelFormat: 3,
    desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
    index: 0
};
X
xu-rui-w 已提交
1697
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { 
X
xu-rui-w 已提交
1698 1699
    console.log('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1700 1701
```

R
renhongwei 已提交
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
### createPixelMapList<sup>10+</sup>

createPixelMapList(options?: DecodingOptions): Promise<Array\<PixelMap>>;

通过图片解码参数创建PixelMap数组。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名   | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
| options  | [DecodingOptions](#decodingoptions7)  | 否   | 解码参数。                 |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
黄开兴 已提交
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
| Promise<Array<[PixelMap](#pixelmap7)>> | 异步返回PixeMap数组。 |

**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980103| If the image data unsupport             |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980118| If the image plugin create failed             |
R
renhongwei 已提交
1733 1734 1735 1736 1737 1738 1739 1740 1741

**示例:**

```js
let decodeOpts = {
    sampleSize: 1,
    editable: true,
    desiredSize: { width: 198, height: 202 },
    rotate: 0,
1742
    desiredPixelFormat: 3,
R
renhongwei 已提交
1743 1744
    index: 0,
};
1745
let pixelmaplist = imageSourceApi.createPixelMapList(decodeOpts);
R
renhongwei 已提交
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
```

### createPixelMapList<sup>10+</sup>

createPixelMapList(callback: AsyncCallback<Array\<PixelMap>>): void

通过默认参数创建PixelMap数组,使用callback形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名     | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 通过回调返回PixelMap数组。 |

黄开兴 已提交
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980103| If the image data unsupport             |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980118| If the image plugin create failed             |

R
renhongwei 已提交
1774 1775 1776
**示例:**

```js
1777
imageSourceApi.createPixelMapList( pixelmaplist => {
R
renhongwei 已提交
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
    console.info('Succeeded in creating pixelmaplist object.');
})
```

### createPixelMapList<sup>10+</sup>

createPixelMapList(options: DecodingOptions, callback: AsyncCallback<Array\<PixelMap>>): void;

通过图片解码参数创建PixelMap数组,使用callback形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名   | 类型                 | 必填 | 说明                               |
| -------- | -------------------- | ---- | ---------------------------------- |
| options | [DecodingOptions](#decodingoptions7) | 是 | 解码参数。 |
| callback | AsyncCallback<Array<[PixelMap](#pixelmap7)>> | 是   | 通过回调返回PixelMap数组。 |

黄开兴 已提交
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980103| If the image data unsupport             |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980118| If the image plugin create failed             |

R
renhongwei 已提交
1809 1810 1811 1812 1813 1814 1815 1816
**示例:**

```js
let decodeOpts = {
    sampleSize: 1,
    editable: true,
    desiredSize: { width: 198, height: 202 },
    rotate: 0,
1817
    desiredPixelFormat: 3,
R
renhongwei 已提交
1818 1819
    index: 0,
};
1820
imageSourceApi.createPixelMapList(decodeOpts, pixelmaplist => { 
R
renhongwei 已提交
1821 1822 1823 1824
    console.log('Succeeded in creating pixelmaplist object.');
})
```

1825
### getDelayTimeList<sup>10+</sup>
R
renhongwei 已提交
1826

1827
getDelayTimeList(callback: AsyncCallback<Array\<number>>): void;
R
renhongwei 已提交
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838

获取图像延迟时间数组,使用callback形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名   | 类型                 | 必填 | 说明                               |
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback<Array\<number>> | 是   | 通过回调返回延迟时间数组。 |

黄开兴 已提交
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980113| If the image format unknown            |
| 62980116| If the image decode failed            |
| 62980118| If the image plugin create failed             |
| 62980122| If the image decode head abnormal             |

R
renhongwei 已提交
1853 1854 1855
**示例:**

```js
1856
imageSourceApi.getDelayTimeList( delayTimes => {
R
renhongwei 已提交
1857 1858 1859 1860
    console.log('Succeeded in getting delay time.');
});
```

1861
### getDelayTimeList<sup>10+</sup>
R
renhongwei 已提交
1862

1863
getDelayTimeList(): Promise<Array\<number>>;
R
renhongwei 已提交
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874

获取图像延迟时间数组,使用Promise形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**返回值:**

| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise<Array\<number>> | Promise实例,异步返回延迟时间数组。 |

黄开兴 已提交
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980113| If the image format unknown            |
| 62980116| If the image decode failed            |
| 62980118| If the image plugin create failed             |
| 62980122| If the image decode head abnormal             |

R
renhongwei 已提交
1889 1890 1891
**示例:**

```js
1892
let delayTimes = imageSourceApi.getDelayTimeList();
R
renhongwei 已提交
1893 1894 1895 1896
```

### getFrameCount<sup>10+</sup>

Z
zengyawen 已提交
1897
getFrameCount(callback: AsyncCallback\<number>): void;
R
renhongwei 已提交
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908

获取图像帧数,使用callback形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**参数:**

| 参数名   | 类型                 | 必填 | 说明                               |
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<number> | 是   | 通过回调返回图像帧数。 |

黄开兴 已提交
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922
**错误码:**

以下错误码的详细介绍请参见[Image错误码](../errorcodes/errorcode-image.md)

| 错误码ID | 错误信息 |
| ------- | --------------------------------------------|
| 62980096| If the operation invalid              |
| 62980110| If the image source data error              |
| 62980111| If the image source data incomplete            |
| 62980113| If the image format unknown            |
| 62980116| If the image decode failed            |
| 62980118| If the image plugin create failed             |
| 62980122| If the image decode head abnormal             |

R
renhongwei 已提交
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
**示例:**

```js
imageSourceApi.getFrameCount( frameCount => {
    console.log('Succeeded in getting frame count.');
});
```

### getFrameCount<sup>10+</sup>

getFrameCount(): Promise\<number>;

获取图像帧数,使用Promise形式返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageSource

**返回值:**

| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<number> | Promise实例,异步返回图像帧数。 |

**示例:**

```js
1948
let frameCount = imageSourceApi.getFrameCount();
R
renhongwei 已提交
1949 1950
```

Z
zengyawen 已提交
1951
### release
X
xiaok 已提交
1952

Z
zengyawen 已提交
1953
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
1954

Z
zengyawen 已提交
1955
释放图片源实例,使用callback形式返回结果。
X
xiaok 已提交
1956

X
xu-rui-w 已提交
1957
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1958 1959 1960

**参数:**

1961
| 参数名   | 类型                 | 必填 | 说明                               |
Z
zengyawen 已提交
1962 1963
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<void> | 是   | 资源释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1964 1965 1966 1967

**示例:**

```js
X
xu-rui-w 已提交
1968 1969 1970
imageSourceApi.release(() => { 
    console.log('release succeeded.');
})
X
xiaok 已提交
1971 1972
```

Z
zengyawen 已提交
1973
### release
X
xiaok 已提交
1974

Z
zengyawen 已提交
1975
release(): Promise\<void>
X
xiaok 已提交
1976

Z
zengyawen 已提交
1977
释放图片源实例,使用Promise形式返回结果。
X
xiaok 已提交
1978

X
xu-rui-w 已提交
1979
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1980

Z
zengyawen 已提交
1981 1982 1983 1984 1985 1986
**返回值:**

| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |

X
xiaok 已提交
1987 1988 1989
**示例:**

```js
X
xu-rui-w 已提交
1990
imageSourceApi.release().then(()=>{
X
xu-rui-w 已提交
1991
    console.log('Succeeded in releasing the image source instance.');
X
xu-rui-w 已提交
1992
}).catch(error => {
X
xu-rui-w 已提交
1993
    console.log('Failed to release the image source instance.');
X
xu-rui-w 已提交
1994
})
X
xiaok 已提交
1995 1996
```

Z
zengyawen 已提交
1997
## image.createImagePacker
X
xiaok 已提交
1998 1999 2000

createImagePacker(): ImagePacker

Z
zengyawen 已提交
2001
创建ImagePacker实例。
X
xiaok 已提交
2002

X
xu-rui-w 已提交
2003
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
2004 2005 2006

**返回值:**

Z
zengyawen 已提交
2007 2008 2009
| 类型                        | 说明                  |
| --------------------------- | --------------------- |
| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
X
xiaok 已提交
2010 2011 2012 2013 2014 2015 2016

**示例:**

```js
const imagePackerApi = image.createImagePacker();
```

Z
zengyawen 已提交
2017 2018
## ImagePacker

X
xu-rui-w 已提交
2019
图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过createImagePacker构建一个ImagePacker实例,当前支持格式有:jpeg webp。
X
xiaok 已提交
2020

Z
zengyawen 已提交
2021 2022
### 属性

X
xu-rui-w 已提交
2023
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zhang-xiaobo1997 已提交
2024 2025 2026 2027

| 名称             | 类型           | 可读 | 可写 | 说明                       |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | 是   | 否   | 图片打包支持的格式,jpeg。 |
Z
zengyawen 已提交
2028 2029 2030

### packing

2031
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
X
xiaok 已提交
2032 2033 2034

图片压缩或重新打包,使用callback形式返回结果。

X
xu-rui-w 已提交
2035
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
2036 2037 2038

**参数:**

Z
zengyawen 已提交
2039 2040 2041
| 参数名   | 类型                               | 必填 | 说明                               |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
X
xu-rui-w 已提交
2042
| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                      |
2043
| callback | AsyncCallback\<ArrayBuffer>        | 是   | 获取图片打包回调,返回打包后数据。 |
X
xiaok 已提交
2044 2045 2046 2047

**示例:**

```js
F
fengzewu 已提交
2048
const imageSourceApi = image.createImageSource(0);
X
xu-rui-w 已提交
2049
let packOpts = { format:"image/jpeg", quality:98 };
X
xu-rui-w 已提交
2050
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
X
xiaok 已提交
2051 2052
```

Z
zengyawen 已提交
2053
### packing
X
xiaok 已提交
2054

2055
packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
X
xiaok 已提交
2056

Z
zengyawen 已提交
2057
图片压缩或重新打包,使用Promise形式返回结果。
X
xiaok 已提交
2058

X
xu-rui-w 已提交
2059
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
2060 2061 2062 2063 2064

**参数:**

| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
Z
zengyawen 已提交
2065 2066
| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
X
xiaok 已提交
2067 2068 2069

**返回值:**

Z
zengyawen 已提交
2070
| 类型                         | 说明                                          |
X
xu-rui-w 已提交
2071 2072
| ---------------------------- | --------------------------------------------- |
| Promise\<ArrayBuffer>        | Promise实例,用于异步获取压缩或打包后的数据。 |
X
xiaok 已提交
2073 2074 2075 2076

**示例:**

```js
F
fengzewu 已提交
2077
const imageSourceApi = image.createImageSource(0);
X
xu-rui-w 已提交
2078
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
2079
imagePackerApi.packing(imageSourceApi, packOpts)
X
xu-rui-w 已提交
2080 2081 2082 2083 2084
    .then( data => {
        console.log('packing succeeded.');
	}).catch(error => {
	    console.log('packing failed.');
	})
2085 2086
```

2087
### packing<sup>8+</sup>
2088

Z
zengyawen 已提交
2089
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
2090 2091 2092

图片压缩或重新打包,使用callback形式返回结果。

X
xu-rui-w 已提交
2093
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
2094 2095 2096 2097 2098 2099 2100

**参数:**

| 参数名   | 类型                            | 必填 | 说明                               |
| -------- | ------------------------------- | ---- | ---------------------------------- |
| source   | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap资源。               |
| option   | [PackingOption](#packingoption) | 是   | 设置打包参数。                     |
Z
zengyawen 已提交
2101
| callback | AsyncCallback\<ArrayBuffer>     | 是   | 获取图片打包回调,返回打包后数据。 |
2102 2103 2104 2105

**示例:**

```js
X
xu-rui-w 已提交
2106
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
2107 2108 2109 2110
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
    let packOpts = { format:"image/jpeg", quality:98 }
冯泽悟 已提交
2111
    imagePackerApi.packing(pixelmap, packOpts, data => { 
F
fengzewu 已提交
2112 2113
        console.log('Succeeded in packing the image.');
    })
X
xu-rui-w 已提交
2114
})
2115 2116
```

2117
### packing<sup>8+</sup>
2118

2119
packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
2120 2121 2122

图片压缩或重新打包,使用Promise形式返回结果。

X
xu-rui-w 已提交
2123
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
2124 2125 2126

**参数:**

Z
zhang-xiaobo1997 已提交
2127 2128
| 参数名 | 类型                            | 必填 | 说明               |
| ------ | ------------------------------- | ---- | ------------------ |
2129
| source | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap源。 |
Z
zhang-xiaobo1997 已提交
2130
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
2131 2132 2133

**返回值:**

X
xu-rui-w 已提交
2134 2135 2136
| 类型                  | 说明                                         |
| --------------------- | -------------------------------------------- |
| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。|
2137 2138 2139 2140

**示例:**

```js
X
xu-rui-w 已提交
2141
const color = new ArrayBuffer(96);  //96为需要创建的像素buffer大小,取值为:height * width *4
F
fengzewu 已提交
2142 2143 2144 2145
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
    let packOpts = { format:"image/jpeg", quality:98 }
冯泽悟 已提交
2146
    imagePackerApi.packing(pixelmap, packOpts)
F
fengzewu 已提交
2147
        .then( data => {
F
fengzewu 已提交
2148 2149 2150 2151
            console.log('Succeeded in packing the image.');
        }).catch(error => {
            console.log('Failed to pack the image..');
        })
F
fengzewu 已提交
2152
})
X
xiaok 已提交
2153 2154
```

Z
zengyawen 已提交
2155
### release
X
xiaok 已提交
2156

Z
zengyawen 已提交
2157
release(callback: AsyncCallback\<void>): void
X
xiaok 已提交
2158

Z
zengyawen 已提交
2159
释放图片打包实例,使用callback形式返回结果。
X
xiaok 已提交
2160

X
xu-rui-w 已提交
2161
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
2162 2163 2164

**参数:**

Z
zengyawen 已提交
2165 2166 2167
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<void> | 是   | 释放回调,失败时返回错误信息。 |
X
xiaok 已提交
2168 2169 2170 2171

**示例:**

```js
X
xu-rui-w 已提交
2172
imagePackerApi.release(()=>{ 
X
xu-rui-w 已提交
2173
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
2174
})
X
xiaok 已提交
2175 2176
```

Z
zengyawen 已提交
2177
### release
X
xiaok 已提交
2178

Z
zengyawen 已提交
2179
release(): Promise\<void>
X
xiaok 已提交
2180

Z
zengyawen 已提交
2181
释放图片打包实例,使用Promise形式返回释放结果。
X
xiaok 已提交
2182

X
xu-rui-w 已提交
2183
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
2184

Z
zengyawen 已提交
2185 2186
**返回值:**

X
xu-rui-w 已提交
2187 2188 2189
| 类型           | 说明                                                   |
| -------------- | ------------------------------------------------------ |
| Promise\<void> | Promise实例,用于异步获取释放结果,失败时返回错误信息。|
Z
zengyawen 已提交
2190

X
xiaok 已提交
2191 2192 2193
**示例:**

```js
X
xu-rui-w 已提交
2194
imagePackerApi.release().then(()=>{
X
xu-rui-w 已提交
2195
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
2196
}).catch((error)=>{ 
X
xu-rui-w 已提交
2197
    console.log('Failed to release image packaging.'); 
X
xu-rui-w 已提交
2198
}) 
X
xiaok 已提交
2199 2200
```

Z
zhang-xiaobo1997 已提交
2201 2202
## image.createImageReceiver<sup>9+</sup>

Z
zengyawen 已提交
2203
createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
Z
zhang-xiaobo1997 已提交
2204

Z
zengyawen 已提交
2205
通过宽、高、图片格式、容量创建ImageReceiver实例。
Z
zhang-xiaobo1997 已提交
2206

Z
zengyawen 已提交
2207
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2208 2209 2210

**参数:**

2211
| 参数名   | 类型   | 必填 | 说明                   |
Z
zengyawen 已提交
2212 2213 2214
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
Z
zhangqiang183 已提交
2215
| format   | number | 是   | 图像格式,取值为[ImageFormat](#imageformat9)常量(目前仅支持 ImageFormat:JPEG 和 4)。  |
Z
zengyawen 已提交
2216
| capacity | number | 是   | 同时访问的最大图像数。 |
Z
zhang-xiaobo1997 已提交
2217 2218 2219

**返回值:**

Z
zengyawen 已提交
2220 2221 2222
| 类型                             | 说明                                    |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
Z
zhang-xiaobo1997 已提交
2223 2224 2225 2226

**示例:**

```js
X
xu-rui-w 已提交
2227
var receiver = image.createImageReceiver(8192, 8, 2000, 8);
Z
zhang-xiaobo1997 已提交
2228
```
Z
zhang-xiaobo1997 已提交
2229

Z
zhang-xiaobo1997 已提交
2230 2231
## ImageReceiver<sup>9+</sup>

Z
zengyawen 已提交
2232 2233 2234
图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。

在调用以下方法前需要先创建ImageReceiver实例。
Z
zhang-xiaobo1997 已提交
2235 2236 2237

### 属性

X
xu-rui-w 已提交
2238
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2239

X
xu-rui-w 已提交
2240 2241 2242 2243 2244
| 名称     | 类型                         | 可读 | 可写 | 说明               |
| -------- | ---------------------------- | ---- | ---- | ------------------ |
| size     | [Size](#size)                | 是   | 否   | 图片大小。         |
| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
Z
zhang-xiaobo1997 已提交
2245

Z
zhang-xiaobo1997 已提交
2246
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2247

Z
zhang-xiaobo1997 已提交
2248
getReceivingSurfaceId(callback: AsyncCallback\<string>): void
Z
zhang-xiaobo1997 已提交
2249

Z
zengyawen 已提交
2250
用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
Z
zhang-xiaobo1997 已提交
2251

Z
zengyawen 已提交
2252
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2253 2254 2255

**参数:**

2256
| 参数名   | 类型                   | 必填 | 说明                       |
Z
zengyawen 已提交
2257 2258
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是   | 回调函数,返回surface id。 |
Z
zhang-xiaobo1997 已提交
2259 2260 2261 2262

**示例:**

```js
X
xu-rui-w 已提交
2263
receiver.getReceivingSurfaceId((err, id) => { 
X
xu-rui-w 已提交
2264 2265 2266 2267 2268 2269
    if(err) {
        console.log('getReceivingSurfaceId failed.');
    } else {
        console.log('getReceivingSurfaceId succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
2270 2271
```

Z
zhang-xiaobo1997 已提交
2272
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2273

Z
zhang-xiaobo1997 已提交
2274
getReceivingSurfaceId(): Promise\<string>
Z
zhang-xiaobo1997 已提交
2275

Z
zengyawen 已提交
2276
用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
Z
zhang-xiaobo1997 已提交
2277

Z
zengyawen 已提交
2278
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2279 2280 2281

**返回值:**

Z
zhang-xiaobo1997 已提交
2282 2283 2284
| 类型             | 说明                 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
Z
zhang-xiaobo1997 已提交
2285 2286 2287 2288 2289

**示例:**

```js
receiver.getReceivingSurfaceId().then( id => { 
X
xu-rui-w 已提交
2290 2291 2292 2293
    console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
    console.log('getReceivingSurfaceId failed.');
})
Z
zhang-xiaobo1997 已提交
2294 2295
```

Z
zhang-xiaobo1997 已提交
2296
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2297

Z
zhang-xiaobo1997 已提交
2298
readLatestImage(callback: AsyncCallback\<Image>): void
Z
zhang-xiaobo1997 已提交
2299

Z
zengyawen 已提交
2300
从ImageReceiver读取最新的图片,并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
2301

Z
zengyawen 已提交
2302
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2303 2304 2305

**参数:**

2306
| 参数名     | 类型                            | 必填 | 说明                     |
Z
zengyawen 已提交
2307 2308
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回最新图像。 |
Z
zhang-xiaobo1997 已提交
2309 2310 2311 2312

**示例:**

```js
X
xu-rui-w 已提交
2313 2314 2315 2316 2317 2318 2319
receiver.readLatestImage((err, img) => { 
    if(err) {
        console.log('readLatestImage failed.');
    } else {
        console.log('readLatestImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
2320 2321
```

Z
zhang-xiaobo1997 已提交
2322
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2323

Z
zhang-xiaobo1997 已提交
2324
readLatestImage(): Promise\<Image>
Z
zhang-xiaobo1997 已提交
2325

Z
zengyawen 已提交
2326
从ImageReceiver读取最新的图片,并使用promise返回结果。
Z
zhang-xiaobo1997 已提交
2327

Z
zengyawen 已提交
2328
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2329 2330 2331 2332 2333

**返回值:**

| 类型                      | 说明               |
| ------------------------- | ------------------ |
2334
| Promise<[Image](#image9)> | 异步返回最新图片。 |
Z
zhang-xiaobo1997 已提交
2335 2336 2337 2338

**示例:**

```js
X
xu-rui-w 已提交
2339 2340 2341 2342 2343
receiver.readLatestImage().then(img => {
    console.log('readLatestImage succeeded.');
}).catch(error => {
    console.log('readLatestImage failed.');
})
Z
zhang-xiaobo1997 已提交
2344 2345
```

Z
zhang-xiaobo1997 已提交
2346
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2347

Z
zhang-xiaobo1997 已提交
2348
readNextImage(callback: AsyncCallback\<Image>): void
Z
zhang-xiaobo1997 已提交
2349

Z
zengyawen 已提交
2350
从ImageReceiver读取下一张图片,并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
2351

Z
zengyawen 已提交
2352
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2353 2354 2355

**参数:**

2356
| 参数名   | 类型                            | 必填 | 说明                       |
Z
zengyawen 已提交
2357 2358
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
2359 2360 2361 2362

**示例:**

```js
X
xu-rui-w 已提交
2363 2364 2365 2366 2367 2368 2369
receiver.readNextImage((err, img) => { 
    if(err) {
        console.log('readNextImage failed.');
    } else {
        console.log('readNextImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
2370 2371
```

Z
zhang-xiaobo1997 已提交
2372
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2373

Z
zhang-xiaobo1997 已提交
2374
readNextImage(): Promise\<Image>
Z
zhang-xiaobo1997 已提交
2375

Z
zengyawen 已提交
2376
从ImageReceiver读取下一张图片,并使用promise返回结果。
Z
zhang-xiaobo1997 已提交
2377

Z
zengyawen 已提交
2378
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2379 2380 2381 2382 2383

**返回值:**

| 类型                      | 说明                 |
| ------------------------- | -------------------- |
Z
zengyawen 已提交
2384
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
2385 2386 2387 2388

**示例:**

```js
X
xu-rui-w 已提交
2389 2390 2391 2392 2393
receiver.readNextImage().then(img => {
    console.log('readNextImage succeeded.');
}).catch(error => {
    console.log('readNextImage failed.');
})
Z
zhang-xiaobo1997 已提交
2394 2395
```

X
xu-rui-w 已提交
2396
### on<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2397

Z
zhang-xiaobo1997 已提交
2398
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
2399 2400 2401

接收图片时注册回调。

Z
zengyawen 已提交
2402
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2403 2404 2405

**参数:**

2406
| 参数名   | 类型                 | 必填 | 说明                                                   |
Z
zhang-xiaobo1997 已提交
2407
| -------- | -------------------- | ---- | ------------------------------------------------------ |
Z
zengyawen 已提交
2408
| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
Z
zhang-xiaobo1997 已提交
2409
| callback | AsyncCallback\<void> | 是   | 注册的事件回调。                                       |
Z
zhang-xiaobo1997 已提交
2410 2411 2412 2413

**示例:**

```js
X
xu-rui-w 已提交
2414
receiver.on('imageArrival', () => {})
Z
zhang-xiaobo1997 已提交
2415 2416
```

Z
zhang-xiaobo1997 已提交
2417
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2418

Z
zengyawen 已提交
2419
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
2420 2421 2422

释放ImageReceiver实例并使用回调返回结果。

Z
zengyawen 已提交
2423
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2424 2425 2426

**参数:**

2427
| 参数名   | 类型                 | 必填 | 说明                     |
Z
zengyawen 已提交
2428 2429
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是   | 回调函数,返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2430 2431 2432 2433

**示例:**

```js
X
xu-rui-w 已提交
2434
receiver.release(() => {})
Z
zhang-xiaobo1997 已提交
2435 2436
```

Z
zhang-xiaobo1997 已提交
2437
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2438

Z
zhang-xiaobo1997 已提交
2439
release(): Promise\<void>
Z
zhang-xiaobo1997 已提交
2440 2441 2442

释放ImageReceiver实例并使用promise返回结果。

Z
zengyawen 已提交
2443
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2444 2445 2446

**返回值:**

Z
zengyawen 已提交
2447 2448 2449
| 类型           | 说明               |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2450 2451 2452 2453

**示例:**

```js
X
xu-rui-w 已提交
2454 2455 2456 2457 2458
receiver.release().then(() => {
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
2459 2460
```

R
renhongwei 已提交
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470
## image.createImageCreator<sup>9+</sup>

createImageCreator(width: number, height: number, format: number, capacity: number): ImageCreator

通过宽、高、图片格式、容量创建ImageCreator实例。

**系统能力:** SystemCapability.Multimedia.Image.ImageCreator

**参数:**

2471
| 参数名   | 类型   | 必填 | 说明                   |
R
renhongwei 已提交
2472 2473 2474
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
X
xu-rui-w 已提交
2475
| format   | number | 是   | 图像格式,如YCBCR_422_SP,JPEG。             |
R
renhongwei 已提交
2476 2477 2478 2479 2480 2481
| capacity | number | 是   | 同时访问的最大图像数。 |

**返回值:**

| 类型                           | 说明                                    |
| ------------------------------ | --------------------------------------- |
X
xu-rui-w 已提交
2482
| [ImageCreator](#imagecreator9) | 如果操作成功,则返回ImageCreator实例。 |    
R
renhongwei 已提交
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492

**示例:**

```js
var creator = image.createImageCreator(8192, 8, 4, 8);
```

## ImageCreator<sup>9+</sup>

图像创建模块,用于请求图像原生数据区域,并开放给应用编译原生图像数据的能力。
2493
在调用以下方法前需要先创建ImageCreator实例,ImageCreator不支持多线程。
R
renhongwei 已提交
2494 2495 2496

### 属性

X
xu-rui-w 已提交
2497
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507

| 名称     | 类型                         | 可读 | 可写 | 说明               |
| -------- | ---------------------------- | ---- | ---- | ------------------ |
| capacity | number                       | 是   | 否   | 同时访问的图像数。 |
| format   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |

### dequeueImage<sup>9+</sup>

dequeueImage(callback: AsyncCallback\<Image>): void

X
xu-rui-w 已提交
2508
从空闲队列中获取buffer图片,用于绘制UI内容,并使用callback返回结果。
R
renhongwei 已提交
2509

X
xu-rui-w 已提交
2510
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2511 2512 2513

**参数:**

2514
| 参数名        | 类型                                    | 必填 | 说明                 |
R
renhongwei 已提交
2515 2516 2517 2518 2519 2520
| ------------- | ---------------------------------------| ---- | -------------------- |
| callback      | AsyncCallback\<Image>                   | 是   | 回调函数,返回最新图片。 |

**示例:**

```js
X
xu-rui-w 已提交
2521 2522
creator.dequeueImage((err, img) => {
    if (err) {
黄开兴 已提交
2523
        console.info('dequeueImage failed.');
X
xu-rui-w 已提交
2524
    }
2525
    console.info('dequeueImage succeeded.');
X
xu-rui-w 已提交
2526
});
R
renhongwei 已提交
2527 2528 2529 2530 2531 2532
```

### dequeueImage<sup>9+</sup>

dequeueImage(): Promise\<Image>

X
xu-rui-w 已提交
2533
从空闲队列中获取buffer图片,用于绘制UI内容,并使用promise返回结果。
R
renhongwei 已提交
2534

X
xu-rui-w 已提交
2535
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545

**返回值:**

| 类型             | 说明           |
| --------------- | ------------- |
| Promise\<Image> | 返回绘制的图像。 |

**示例:**

```js
X
xu-rui-w 已提交
2546 2547 2548 2549 2550
creator.dequeueImage().then(img => {
    console.info('dequeueImage succeeded.');
}).catch(error => {
    console.log('dequeueImage failed: ' + error);
})
R
renhongwei 已提交
2551 2552
```

X
xu-rui-w 已提交
2553
### queueImage<sup>9+</sup>
R
renhongwei 已提交
2554 2555 2556

queueImage(interface: Image, callback: AsyncCallback\<void>): void

X
xu-rui-w 已提交
2557
将绘制好的图片放入Dirty队列,并使用callback返回结果。
R
renhongwei 已提交
2558

X
xu-rui-w 已提交
2559
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2560 2561 2562

**参数:**

2563
| 参数名        | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2564 2565 2566 2567 2568 2569 2570
| ------------- | -------------------------| ---- | -------------------- |
| interface     | Image                    | 是   | 绘制好的buffer图像。 |
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
2571 2572
creator.dequeueImage().then(img => {
    //绘制图片
2573 2574 2575 2576 2577 2578 2579 2580 2581
    img.getComponent(4).then(component => {
        var bufferArr = new Uint8Array(component.byteBuffer);
        for (var i = 0; i < bufferArr.length; i += 4) {
            bufferArr[i] = 0; //B
            bufferArr[i + 1] = 0; //G
            bufferArr[i + 2] = 255; //R
            bufferArr[i + 3] = 255; //A
        }
    })
2582 2583 2584 2585 2586 2587
    creator.queueImage(img, (err) => {
        if (err) {
            console.info('queueImage failed: ' + err);
        }
        console.info('queueImage succeeded');
    })
2588 2589
})

R
renhongwei 已提交
2590 2591
```

X
xu-rui-w 已提交
2592
### queueImage<sup>9+</sup>
R
renhongwei 已提交
2593 2594 2595

queueImage(interface: Image): Promise\<void>

X
xu-rui-w 已提交
2596
将绘制好的图片放入Dirty队列,并使用promise返回结果。
R
renhongwei 已提交
2597

X
xu-rui-w 已提交
2598
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2599 2600 2601

**参数:**

2602
| 参数名          | 类型     | 必填 | 说明                |
R
renhongwei 已提交
2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614
| ------------- | --------| ---- | ------------------- |
| interface     | Image   | 是   | 绘制好的buffer图像。 |

**返回值:**

| 类型            | 说明           |
| -------------- | ------------- |
| Promise\<void> | 获取回调,失败时返回错误信息。 |

**示例:**

```js
2615 2616
creator.dequeueImage().then(img => {
    //绘制图片
2617 2618 2619 2620 2621 2622 2623 2624 2625
    img.getComponent(4).then(component => {
        var bufferArr = new Uint8Array(component.byteBuffer);
        for (var i = 0; i < bufferArr.length; i += 4) {
            bufferArr[i] = 0; //B
            bufferArr[i + 1] = 0; //G
            bufferArr[i + 2] = 255; //R
            bufferArr[i + 3] = 255; //A
        }
    })
2626 2627 2628 2629 2630
    creator.queueImage(img).then(() => {
        console.info('queueImage succeeded.');
    }).catch(error => {
        console.info('queueImage failed: ' + error);
    })
X
xu-rui-w 已提交
2631
})
2632

R
renhongwei 已提交
2633 2634 2635 2636 2637 2638 2639 2640
```

### on<sup>9+</sup>

on(type: 'imageRelease', callback: AsyncCallback\<void>): void

监听imageRelease事件,并使用callback返回结果。

X
xu-rui-w 已提交
2641
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2642 2643 2644

**参数:**

2645
| 参数名        | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2646
| ------------- | -------------------------| ---- | -------------------- |
X
xu-rui-w 已提交
2647
| type          | string                   | 是   | 监听事件类型,如'imageRelease'。 |
R
renhongwei 已提交
2648 2649 2650 2651 2652
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2653 2654 2655 2656 2657 2658
creator.on('imageRelease', (err) => {
    if (err) {
        console.info('on faild' + err);
    }
    console.info('on succeeded');
})
R
renhongwei 已提交
2659 2660 2661 2662 2663 2664 2665 2666
```

### release<sup>9+</sup>

release(callback: AsyncCallback\<void>): void

释放当前图像,并使用callback返回结果。

X
xu-rui-w 已提交
2667
**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2668 2669 2670

**参数:**

2671
| 参数名           | 类型                     | 必填 | 说明                 |
R
renhongwei 已提交
2672 2673 2674 2675 2676 2677
| ------------- | -------------------------| ---- | -------------------- |
| callback      | AsyncCallback\<void>     | 是   | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2678 2679 2680 2681 2682 2683
creator.release((err) => {
    if (err) {
        console.info('release failed: ' + err);
    }
    console.info('release succeeded');
});
R
renhongwei 已提交
2684 2685 2686 2687 2688
```
### release<sup>9+</sup>

release(): Promise\<void>

X
xu-rui-w 已提交
2689 2690 2691
释放当前图像,并使用promise返回结果。

**系统能力:** SystemCapability.Multimedia.Image.ImageCreator
R
renhongwei 已提交
2692 2693 2694 2695 2696 2697 2698 2699 2700 2701

**返回值:**

| 类型            | 说明           |
| -------------- | ------------- |
| Promise\<void> | 获取回调,失败时返回错误信息。 |

**示例:**

```js
X
xu-rui-w 已提交
2702 2703 2704 2705 2706
creator.release().then(() => {
    console.info('release succeeded');
}).catch(error => {
    console.info('release failed');
})
R
renhongwei 已提交
2707 2708
```

Z
zhang-xiaobo1997 已提交
2709
## Image<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2710

Z
zengyawen 已提交
2711
提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)[readLatestImage](#readlatestimage9)接口时会返回image。
Z
zhang-xiaobo1997 已提交
2712 2713 2714

### 属性

X
xu-rui-w 已提交
2715
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2716

X
xu-rui-w 已提交
2717 2718 2719
| 名称     | 类型               | 可读 | 可写 | 说明                                               |
| -------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect | [Region](#region7) | 是   | 是   | 要裁剪的图像区域。                                 |
X
xu-rui-w 已提交
2720
| size     | [Size](#size)      | 是   | 否   | 图像大小。                                         |
X
xu-rui-w 已提交
2721
| format   | number             | 是   | 否   | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 |
Z
zhang-xiaobo1997 已提交
2722

Z
zhang-xiaobo1997 已提交
2723
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2724

Z
zhang-xiaobo1997 已提交
2725
getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
Z
zhang-xiaobo1997 已提交
2726

Z
zhang-xiaobo1997 已提交
2727
根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
Z
zhang-xiaobo1997 已提交
2728

Z
zengyawen 已提交
2729
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2730 2731 2732

**参数:**

2733
| 参数名        | 类型                                    | 必填 | 说明                 |
Z
zhang-xiaobo1997 已提交
2734
| ------------- | --------------------------------------- | ---- | -------------------- |
Z
zengyawen 已提交
2735 2736
| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。     |
| callback      | AsyncCallback<[Component](#component9)> | 是   | 用于返回组件缓冲区。 |
Z
zhang-xiaobo1997 已提交
2737 2738 2739 2740

**示例:**

```js
X
xu-rui-w 已提交
2741 2742 2743 2744 2745 2746 2747
img.getComponent(4, (err, component) => {
    if(err) {
        console.log('getComponent failed.');
    } else {
        console.log('getComponent succeeded.');
    }
})
Z
zhang-xiaobo1997 已提交
2748 2749
```

Z
zhang-xiaobo1997 已提交
2750
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2751

Z
zhang-xiaobo1997 已提交
2752
getComponent(componentType: ComponentType): Promise\<Component>
Z
zhang-xiaobo1997 已提交
2753

Z
zengyawen 已提交
2754
根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
Z
zhang-xiaobo1997 已提交
2755

Z
zengyawen 已提交
2756
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2757 2758 2759

**参数:**

2760
| 参数名        | 类型                             | 必填 | 说明             |
Z
zhang-xiaobo1997 已提交
2761
| ------------- | -------------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
2762
| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。 |
Z
zhang-xiaobo1997 已提交
2763 2764 2765 2766 2767

**返回值:**

| 类型                              | 说明                              |
| --------------------------------- | --------------------------------- |
Z
zengyawen 已提交
2768
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
Z
zhang-xiaobo1997 已提交
2769 2770 2771 2772 2773 2774 2775

**示例:**

```js
img.getComponent(4).then(component => { })
```

Z
zhang-xiaobo1997 已提交
2776
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2777

Z
zhang-xiaobo1997 已提交
2778
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
2779

Z
zengyawen 已提交
2780 2781 2782
释放当前图像并使用callback返回结果。

在接收另一个图像前必须先释放对应资源。
Z
zhang-xiaobo1997 已提交
2783

Z
zengyawen 已提交
2784
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2785 2786 2787

**参数:**

2788
| 参数名   | 类型                 | 必填 | 说明           |
Z
zhang-xiaobo1997 已提交
2789 2790
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是   | 返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2791 2792 2793 2794

**示例:**

```js
X
xu-rui-w 已提交
2795 2796 2797
img.release(() =>{ 
    console.log('release succeeded.');
}) 
Z
zhang-xiaobo1997 已提交
2798 2799
```

Z
zhang-xiaobo1997 已提交
2800
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2801

Z
zhang-xiaobo1997 已提交
2802
release(): Promise\<void>
Z
zhang-xiaobo1997 已提交
2803

Z
zengyawen 已提交
2804 2805 2806
释放当前图像并使用Promise方式返回结果。

在接收另一个图像前必须先释放对应资源。
Z
zhang-xiaobo1997 已提交
2807

Z
zengyawen 已提交
2808
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2809 2810 2811

**返回值:**

Z
zhang-xiaobo1997 已提交
2812 2813 2814
| 类型           | 说明                  |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2815 2816 2817 2818 2819

**示例:**

```js
img.release().then(() =>{
X
xu-rui-w 已提交
2820 2821 2822 2823
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
2824 2825
```

Z
zengyawen 已提交
2826 2827 2828 2829
## PositionArea<sup>7+</sup>

表示图片指定区域内的数据。

X
xu-rui-w 已提交
2830
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2831

2832 2833 2834 2835
| 名称   | 类型               | 可读 | 可写 | 说明                                                         |
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer        | 是   | 否   | 像素。                                                       |
| offset | number             | 是   | 否   | 偏移量。                                                     |
X
xu-rui-w 已提交
2836
| stride | number             | 是   | 否   | 像素间距,stride >= region.size.width*4。                   |
X
xu-rui-w 已提交
2837
| region | [Region](#region7) | 是   | 否   | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度。 |
X
xiaok 已提交
2838

Z
zengyawen 已提交
2839
## ImageInfo
X
xiaok 已提交
2840

Z
zengyawen 已提交
2841
表示图片信息。
X
xiaok 已提交
2842

X
xu-rui-w 已提交
2843
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2844

Z
zengyawen 已提交
2845 2846 2847
| 名称 | 类型          | 可读 | 可写 | 说明       |
| ---- | ------------- | ---- | ---- | ---------- |
| size | [Size](#size) | 是   | 是   | 图片大小。 |
X
xu-rui-w 已提交
2848
| density<sup>9+</sup> | number | 是   | 是   | 像素密度,单位为ppi。 |
X
xiaok 已提交
2849

Z
zengyawen 已提交
2850
## Size
X
xiaok 已提交
2851

Z
zengyawen 已提交
2852 2853
表示图片尺寸。

X
xu-rui-w 已提交
2854
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2855 2856 2857 2858 2859 2860 2861

| 名称   | 类型   | 可读 | 可写 | 说明           |
| ------ | ------ | ---- | ---- | -------------- |
| height | number | 是   | 是   | 输出图片的高。 |
| width  | number | 是   | 是   | 输出图片的宽。 |

## PixelMapFormat<sup>7+</sup>
X
xiaok 已提交
2862

Z
zengyawen 已提交
2863
枚举,图片像素格式。
X
xiaok 已提交
2864

X
xu-rui-w 已提交
2865
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2866

2867
| 名称                   |   值   | 说明              |
X
xu-rui-w 已提交
2868 2869 2870
| ---------------------- | ------ | ----------------- |
| UNKNOWN                | 0      | 未知格式。        |
| RGB_565                | 2      | 格式为RGB_565     |
X
xu-rui-w 已提交
2871 2872 2873 2874 2875 2876 2877
| RGBA_8888              | 3      | 格式为RGBA_8888 |
| BGRA_8888<sup>9+</sup> | 4      | 格式为BGRA_8888 |
| RGB_888<sup>9+</sup>   | 5      | 格式为RGB_888   |
| ALPHA_8<sup>9+</sup>   | 6      | 格式为ALPHA_8   |
| RGBA_F16<sup>9+</sup>  | 7      | 格式为RGBA_F16  |
| NV21<sup>9+</sup>      | 8      | 格式为NV21      |
| NV12<sup>9+</sup>      | 9      | 格式为NV12      |
Z
zengyawen 已提交
2878

2879
## AlphaType<sup>9+</sup>
X
xiaok 已提交
2880

Z
zengyawen 已提交
2881
枚举,图像的透明度类型。
X
xiaok 已提交
2882

X
xu-rui-w 已提交
2883
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2884

2885
| 名称     |   值   | 说明                    |
Z
zengyawen 已提交
2886 2887 2888
| -------- | ------ | ----------------------- |
| UNKNOWN  | 0      | 未知透明度。            |
| OPAQUE   | 1      | 没有alpha或图片全透明。 |
X
xu-rui-w 已提交
2889 2890
| PREMUL   | 2      | RGB前乘alpha。         |
| UNPREMUL | 3      | RGB不前乘alpha。       |
X
xiaok 已提交
2891

2892
## ScaleMode<sup>9+</sup>
X
xiaok 已提交
2893

Z
zengyawen 已提交
2894
枚举,图像的缩放模式。
X
xiaok 已提交
2895

X
xu-rui-w 已提交
2896
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2897

2898
| 名称            |   值   | 说明                                               |
Z
zengyawen 已提交
2899 2900
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
X
xu-rui-w 已提交
2901
| FIT_TARGET_SIZE | 0      | 图像适合目标尺寸的效果。                           |
X
xiaok 已提交
2902

X
xu-rui-w 已提交
2903 2904 2905 2906
## SourceOptions<sup>9+</sup>

ImageSource的初始化选项。

X
xu-rui-w 已提交
2907
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xu-rui-w 已提交
2908

X
xu-rui-w 已提交
2909 2910 2911 2912 2913
| 名称              | 类型                               | 可读 | 可写 | 说明               |
| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
| sourceDensity     | number                             | 是   | 是   | ImageSource的密度。|
| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 图片像素格式。     |
| sourceSize        | [Size](#size)                      | 是   | 是   | 图像像素大小。     |
X
xu-rui-w 已提交
2914 2915


Z
zengyawen 已提交
2916
## InitializationOptions<sup>8+</sup>
X
xiaok 已提交
2917

Z
zengyawen 已提交
2918 2919
PixelMap的初始化选项。

X
xu-rui-w 已提交
2920
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2921

X
xu-rui-w 已提交
2922 2923 2924
| 名称                     | 类型                               | 可读 | 可写 | 说明           |
| ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | 是   | 是   | 透明度。       |
X
xu-rui-w 已提交
2925 2926
| editable                 | boolean                            | 是   | 是   | 是否可编辑。   |
| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 像素格式。     |
X
xu-rui-w 已提交
2927
| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | 是   | 是   | 缩略值。       |
X
xu-rui-w 已提交
2928
| size                     | [Size](#size)                      | 是   | 是   | 创建图片大小。 |
Z
zengyawen 已提交
2929 2930

## DecodingOptions<sup>7+</sup>
X
xiaok 已提交
2931

Z
zengyawen 已提交
2932
图像解码设置选项。
X
xiaok 已提交
2933

X
xu-rui-w 已提交
2934
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2935 2936 2937

| 名称               | 类型                               | 可读 | 可写 | 说明             |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
2938
| sampleSize         | number                             | 是   | 是   | 缩略图采样大小,当前只能取1。 |
Z
zengyawen 已提交
2939
| rotate             | number                             | 是   | 是   | 旋转角度。       |
2940
| editable           | boolean                            | 是   | 是   | 是否可编辑。当取值为false时,图片不可二次编辑,如crop等操作将失败。  |
Z
zengyawen 已提交
2941
| desiredSize        | [Size](#size)                      | 是   | 是   | 期望输出大小。   |
2942
| desiredRegion      | [Region](#region7)                 | 是   | 是   | 解码区域。       |
Z
zengyawen 已提交
2943
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 解码的像素格式。 |
X
xu-rui-w 已提交
2944
| index              | number                             | 是   | 是   | 解码图片序号。   |
X
xu-rui-w 已提交
2945
| fitDensity<sup>9+</sup> | number                        | 是   | 是   | 图像像素密度,单位为ppi。   |
Z
zengyawen 已提交
2946

2947
## Region<sup>7+</sup>
Z
zengyawen 已提交
2948 2949 2950

表示区域信息。

X
xu-rui-w 已提交
2951
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2952

2953 2954 2955 2956 2957
| 名称 | 类型          | 可读 | 可写 | 说明         |
| ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | 是   | 是   | 区域大小。   |
| x    | number        | 是   | 是   | 区域横坐标。 |
| y    | number        | 是   | 是   | 区域纵坐标。 |
Z
zengyawen 已提交
2958 2959 2960 2961 2962

## PackingOption

表示图片打包选项。

X
xu-rui-w 已提交
2963
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zengyawen 已提交
2964

X
xu-rui-w 已提交
2965 2966
| 名称    | 类型   | 可读 | 可写 | 说明                                                |
| ------- | ------ | ---- | ---- | --------------------------------------------------- |
R
renhongwei 已提交
2967
| format  | string | 是   | 是   | 目标格式。</br>当前只支持jpg和webp。 |
X
xu-rui-w 已提交
2968
| quality | number | 是   | 是   | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
2969
| bufferSize<sup>9+</sup> | number | 是   | 是   | 用于设置图片大小,默认为10M。 |
Z
zengyawen 已提交
2970 2971 2972 2973 2974

## GetImagePropertyOptions<sup>7+</sup>

表示查询图片属性的索引。

X
xu-rui-w 已提交
2975
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985

| 名称         | 类型   | 可读 | 可写 | 说明         |
| ------------ | ------ | ---- | ---- | ------------ |
| index        | number | 是   | 是   | 图片序号。   |
| defaultValue | string | 是   | 是   | 默认属性值。 |

## PropertyKey<sup>7+</sup>

枚举,Exif(Exchangeable image file format)图片信息。

X
xu-rui-w 已提交
2986
**系统能力:** SystemCapability.Multimedia.Image.Core
2987

2988
| 名称              |   值                    | 说明                     |
X
xu-rui-w 已提交
2989 2990 2991 2992 2993 2994 2995
| ----------------- | ----------------------- | ------------------------ |
| BITS_PER_SAMPLE   | "BitsPerSample"         | 每个像素比特数。         |
| ORIENTATION       | "Orientation"           | 图片方向。               |
| IMAGE_LENGTH      | "ImageLength"           | 图片长度。               |
| IMAGE_WIDTH       | "ImageWidth"            | 图片宽度。               |
| GPS_LATITUDE      | "GPSLatitude"           | 图片纬度。               |
| GPS_LONGITUDE     | "GPSLongitude"          | 图片经度。               |
X
xu-rui-w 已提交
2996 2997
| GPS_LATITUDE_REF  | "GPSLatitudeRef"        | 纬度引用,例如N或S。    |
| GPS_LONGITUDE_REF | "GPSLongitudeRef"       | 经度引用,例如W或E。    |
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025
| DATE_TIME_ORIGINAL<sup>9+</sup> | "DateTimeOriginal" | 拍摄时间,例如2022:09:06 15:48:00。当前为只读属性。     |
| EXPOSURE_TIME<sup>9+</sup>      | "ExposureTime"     | 曝光时间,例如1/33 sec。当前为只读属性。 |
| SCENE_TYPE<sup>9+</sup>         | "SceneType"        | 拍摄场景模式,例如人像、风光、运动、夜景等。当前为只读属性。      |
| ISO_SPEED_RATINGS<sup>9+</sup>  | "ISOSpeedRatings"  | ISO感光度,例如400。当前为只读属性。      |
| F_NUMBER<sup>9+</sup>           | "FNumber"          | 光圈值,例如f/1.8。当前为只读属性。      |
| DATE_TIME<sup>10+</sup>                  | "DateTime"             | 日期时间,当前为只读属性。                |
| GPS_TIME_STAMP<sup>10+</sup>             | "GPSTimeStamp"         | GPS时间戳,当前为只读属性。         |
| GPS_DATE_STAMP<sup>10+</sup>             | "GPSDateStamp"         | GPS日期戳,当前为只读属性。          |
| IMAGE_DESCRIPTION<sup>10+</sup>          | "ImageDescription"     | 图像信息描述,当前为只读属性。               |
| MAKE<sup>10+</sup>                       | "Make"                 | 生产商,当前为只读属性。                  |
| PHOTO_MODE<sup>10+</sup>                 | "PhotoMode "           | 拍照模式,当前为只读属性。              |
| SENSITIVITY_TYPE<sup>10+</sup>           | "SensitivityType"      | 灵敏度类型,当前为只读属性。             |
| STANDARD_OUTPUT_SENSITIVITY<sup>10+</sup>           | "StandardOutputSensitivity"          | 标准输出灵敏度,当前为只读属性。    |
| RECOMMENDED_EXPOSURE_INDEX<sup>10+</sup>            | "RecommendedExposureIndex"          | 推荐曝光指数,当前为只读属性。    |
| ISO_SPEED<sup>10+</sup>                             | "ISOSpeedRatings"          | ISO速度等级,当前为只读属性。    |
| APERTURE_VALUE<sup>10+</sup>             | "ApertureValue"            | 光圈值,当前为只读属性。    |
| EXPOSURE_BIAS_VALUE<sup>10+</sup>        | "ExposureBiasValue"        | 曝光偏差值,当前为只读属性。    |
| METERING_MODE<sup>10+</sup>              | "MeteringMode"             | 测光模式,当前为只读属性。    |
| LIGHT_SOURCE<sup>10+</sup>               | "LightSource"              | 光源,当前为只读属性。    |
| FLASH <sup>10+</sup>                     | "Flash"                    | 闪光灯,记录闪光灯状态,当前为只读属性。    |
| FOCAL_LENGTH <sup>10+</sup>              | "FocalLength"              | 焦距,当前为只读属性。    |
| USER_COMMENT <sup>10+</sup>               | "UserComment"              | 用户注释,当前为只读属性。    |
| PIXEL_X_DIMENSION <sup>10+</sup>          | "PixelXDimension"          | 像素X尺寸,当前为只读属性。   |
| PIXEL_Y_DIMENSION<sup>10+</sup>           | "PixelYDimension"          | 像素Y尺寸,当前为只读属性。    |
| WHITE_BALANCE <sup>10+</sup>              | "WhiteBalance"             | 白平衡,当前为只读属性。    |
| FOCAL_LENGTH_IN_35_MM_FILM <sup>10+</sup> | "FocalLengthIn35mmFilm"    | 焦距35毫米胶片,当前为只读属性。    |
| CAPTURE_MODE <sup>10+</sup>               | "HwMnoteCaptureMode"       | 捕获模式,当前为只读属性。    |
| PHYSICAL_APERTURE <sup>10+</sup>          | "HwMnotePhysicalAperture"  | 物理孔径,光圈大小,当前为只读属性。   |
3026

Z
zhang-xiaobo1997 已提交
3027
## ImageFormat<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
3028 3029 3030

枚举,图片格式。

X
xu-rui-w 已提交
3031
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
3032

3033
| 名称         |   值   | 说明                 |
Z
zengyawen 已提交
3034 3035 3036
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
| JPEG         | 2000   | JPEG编码格式。       |
Z
zhang-xiaobo1997 已提交
3037

Z
zengyawen 已提交
3038
## ComponentType<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
3039 3040 3041

枚举,图像的组件类型。

X
xu-rui-w 已提交
3042
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
3043

3044
| 名称  |   值   | 说明        |
Z
zhang-xiaobo1997 已提交
3045 3046 3047 3048
| ----- | ------ | ----------- |
| YUV_Y | 1      | 亮度信息。  |
| YUV_U | 2      | 色度信息。  |
| YUV_V | 3      | 色度信息。  |
X
xu-rui-w 已提交
3049
| JPEG  | 4      | JPEG 类型。 |
Z
zhang-xiaobo1997 已提交
3050

Z
zengyawen 已提交
3051
## Component<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
3052 3053 3054

描述图像颜色分量。

X
xu-rui-w 已提交
3055
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
3056 3057 3058

| 名称          | 类型                             | 可读 | 可写 | 说明         |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
Z
zengyawen 已提交
3059
| componentType | [ComponentType](#componenttype9) | 是   | 否   | 组件类型。   |
Z
zhang-xiaobo1997 已提交
3060 3061 3062 3063
| rowStride     | number                           | 是   | 否   | 行距。       |
| pixelStride   | number                           | 是   | 否   | 像素间距。   |
| byteBuffer    | ArrayBuffer                      | 是   | 否   | 组件缓冲区。 |

3064 3065 3066
## 补充说明
### SVG标签说明

黄开兴 已提交
3067
从API version 10开始支持SVG标签,使用版本为(SVG) 1.1,当前支持的标签列表有:
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105
- a
- circla
- clipPath
- defs
- ellipse
- feBlend
- feColorMatrix
- feComposite
- feDiffuseLighting
- feDisplacementMap
- feDistantLight
- feFlood
- feGaussianBlur
- feImage
- feMorphology
- feOffset
- fePointLight
- feSpecularLighting
- feSpotLight
- feTurbulence
- filter
- g
- image
- line
- linearGradient
- mask
- path
- pattern
- polygon
- polyline
- radialGradient
- rect
- stop
- svg
- text
- textPath
- tspan
- use