js-apis-image.md 75.7 KB
Newer Older
Z
zengyawen 已提交
1
# 图片处理
X
xiaok 已提交
2

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

Z
zengyawen 已提交
6
## 导入模块
X
xiaok 已提交
7

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

X
xu-rui-w 已提交
12
## image.createPixelMap<sup>8+</sup>
X
xu-rui-w 已提交
13

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

Z
zengyawen 已提交
16
通过属性创建PixelMap,通过Promise返回结果。
X
xiaok 已提交
17

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

**参数:**

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

**返回值:**

Z
zengyawen 已提交
29 30
| 类型                             | 说明           |
| -------------------------------- | -------------- |
Z
zengyawen 已提交
31
| Promise\<[PixelMap](#pixelmap7)> | 返回Pixelmap。 |
X
xiaok 已提交
32 33 34 35

**示例:**

```js
X
xu-rui-w 已提交
36
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
37
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
38 39 40 41
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then((pixelmap) => {
        })
X
xiaok 已提交
42 43
```

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

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

Z
zengyawen 已提交
48
通过属性创建PixelMap,通过回调函数返回结果。
X
xiaok 已提交
49

X
xu-rui-w 已提交
50
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
51 52 53

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
63
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
64
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
65 66 67
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => {
        })
X
xiaok 已提交
68 69
```

Z
zengyawen 已提交
70
## PixelMap<sup>7+</sup>
Z
zengyawen 已提交
71 72 73 74 75

图像像素类,用于读取或写入图像数据以及获取图像信息。在调用PixelMap的方法前,需要先通过createPixelMap创建一个PixelMap实例。

 ### 属性

X
xu-rui-w 已提交
76
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
77 78 79 80

| 名称                    | 类型    | 可读 | 可写 | 说明                       |
| ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | 是   | 否   | 设定是否图像像素可被编辑。 |
Z
zengyawen 已提交
81

Z
zengyawen 已提交
82
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
83

Z
zengyawen 已提交
84
readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
X
xiaok 已提交
85 86 87

读取图像像素数据,结果写入ArrayBuffer里,使用Promise形式返回。

X
xu-rui-w 已提交
88
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
89 90 91 92 93 94 95 96 97

**参数:**

| 参数名 | 类型        | 必填 | 说明                                                         |
| ------ | ----------- | ---- | ------------------------------------------------------------ |
| dst    | ArrayBuffer | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。 |

**返回值:**

Z
zengyawen 已提交
98 99 100
| 类型           | 说明                                            |
| :------------- | :---------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
101 102 103 104

**示例:**

```js
X
xu-rui-w 已提交
105 106 107
const readBuffer = new ArrayBuffer(400);
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
    console.log('Succeeded in reading image pixel data.');  //符合条件则进入 
X
xu-rui-w 已提交
108
}).catch(error => {
X
xu-rui-w 已提交
109
    console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
110
})
X
xiaok 已提交
111 112
```

Z
zengyawen 已提交
113
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
114

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

Z
zengyawen 已提交
117
读取图像像素数据,结果写入ArrayBuffer里,使用callback形式返回。
X
xiaok 已提交
118

X
xu-rui-w 已提交
119
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
120 121 122

**参数:**

Z
zengyawen 已提交
123 124 125 126
| 参数名   | 类型                 | 必填 | 说明                                                         |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| dst      | ArrayBuffer          | 是   | 缓冲区,函数执行结束后获取的图像像素数据写入到该内存区域内。 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。                               |
X
xiaok 已提交
127 128 129 130

**示例:**

```js
X
xu-rui-w 已提交
131 132
const readBuffer = new ArrayBuffer(400);
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
X
xu-rui-w 已提交
133
    if(err) {
X
xu-rui-w 已提交
134
        console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
135
    } else {
X
xu-rui-w 已提交
136
        console.log('Succeeded in reading image pixel data.');  //符合条件则进入
X
xu-rui-w 已提交
137 138
    }
})
X
xiaok 已提交
139 140
```

Z
zengyawen 已提交
141
### readPixels<sup>7+</sup>
X
xiaok 已提交
142

Z
zengyawen 已提交
143
readPixels(area: PositionArea): Promise\<void>
X
xiaok 已提交
144 145 146

读取区域内的图片数据,使用Promise形式返回读取结果。

X
xu-rui-w 已提交
147
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
148 149 150

**参数:**

Z
zengyawen 已提交
151 152 153
| 参数名 | 类型                           | 必填 | 说明                     |
| ------ | ------------------------------ | ---- | ------------------------ |
| area   | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。 |
X
xiaok 已提交
154 155 156

**返回值:**

Z
zengyawen 已提交
157 158 159
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取读取结果,失败时返回错误信息。 |
X
xiaok 已提交
160 161 162 163

**示例:**

```js
X
xu-rui-w 已提交
164 165 166
const area = new ArrayBuffer(400);
pixelmap.readPixels(area).then(() => {
    console.log('Succeeded in reading the image data in the area.'); //符合条件则进入
X
xu-rui-w 已提交
167
}).catch(error => {
X
xu-rui-w 已提交
168
    console.log('Failed to read the image data in the area.'); //不符合条件则进入
X
xu-rui-w 已提交
169
})
X
xiaok 已提交
170 171
```

Z
zengyawen 已提交
172
### readPixels<sup>7+</sup>
X
xiaok 已提交
173

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

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

X
xu-rui-w 已提交
178
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
179 180 181

**参数:**

Z
zengyawen 已提交
182 183 184 185
| 参数名   | 类型                           | 必填 | 说明                           |
| -------- | ------------------------------ | ---- | ------------------------------ |
| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
| callback | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
186 187 188 189

**示例:**

```js
X
xu-rui-w 已提交
190
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
191
let bufferArr = new Uint8Array(color);
192 193
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
X
xu-rui-w 已提交
194 195 196 197 198 199 200 201 202 203 204
    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');
        })
    }
205
})
X
xiaok 已提交
206 207
```

Z
zengyawen 已提交
208
### writePixels<sup>7+</sup>
X
xiaok 已提交
209

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

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

X
xu-rui-w 已提交
214
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
215 216 217

**参数:** 

Z
zengyawen 已提交
218 219
| 参数名 | 类型                           | 必填 | 说明                 |
| ------ | ------------------------------ | ---- | -------------------- |
Z
zengyawen 已提交
220
| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
X
xiaok 已提交
221 222 223

**返回值:**

Z
zengyawen 已提交
224 225 226
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取写入结果,失败时返回错误信息。 |
X
xiaok 已提交
227 228 229 230

**示例:**

```js
231
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
232
let bufferArr = new Uint8Array(color);
233 234 235 236
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then( pixelmap => {
        if (pixelmap == undefined) {
X
xu-rui-w 已提交
237
            console.info('createPixelMap failed.');
238 239 240 241 242 243
        }
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
        }
X
xu-rui-w 已提交
244
        let bufferArr = new Uint8Array(area.pixels);
245 246 247 248 249 250 251 252 253 254 255 256
        for (var i = 0; i < bufferArr.length; i++) {
            bufferArr[i] = i + 1;
        }

        pixelmap.writePixels(area).then(() => {
            const readArea = { pixels: new ArrayBuffer(8),
                offset: 0,
                stride: 8,
                // region.size.width + x < opts.width, region.size.height + y < opts.height
                region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
            }        
        })
X
xu-rui-w 已提交
257
    }).catch(error => {
258 259
        console.log('error: ' + error);
    })
X
xiaok 已提交
260 261
```

Z
zengyawen 已提交
262
### writePixels<sup>7+</sup>
X
xiaok 已提交
263

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

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

X
xu-rui-w 已提交
268
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
269 270 271

**参数:** 

Z
zengyawen 已提交
272 273
| 参数名    | 类型                           | 必填 | 说明                           |
| --------- | ------------------------------ | ---- | ------------------------------ |
Z
zengyawen 已提交
274
| area      | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。           |
X
xu-rui-w 已提交
275
| callback: | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
276 277 278 279

**示例:**

```js
X
xu-rui-w 已提交
280 281
const area = new ArrayBuffer(400);
pixelmap.writePixels(area, (error) => {
X
xu-rui-w 已提交
282
    if (error != undefined) {
X
xu-rui-w 已提交
283
		console.info('Failed to write pixelmap into the specified area.');
X
xu-rui-w 已提交
284 285 286 287 288 289 290 291
	} else {
	    const readArea = {
            pixels: new ArrayBuffer(20),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
        }
	}
X
xu-rui-w 已提交
292
})
X
xiaok 已提交
293 294
```

Z
zengyawen 已提交
295
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
296

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

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

X
xu-rui-w 已提交
301
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
302 303 304

**参数:**

Z
zengyawen 已提交
305 306 307
| 参数名 | 类型        | 必填 | 说明           |
| ------ | ----------- | ---- | -------------- |
| src    | ArrayBuffer | 是   | 图像像素数据。 |
X
xiaok 已提交
308 309 310

**返回值:**

Z
zengyawen 已提交
311 312 313
| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
314 315 316 317

**示例:**

```js
X
xu-rui-w 已提交
318
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
319
const pixelMap = new ArrayBuffer(400);
X
xu-rui-w 已提交
320
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
321
pixelMap.writeBufferToPixels(color).then(() => {
X
xiaok 已提交
322 323 324
    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 已提交
325
})
X
xiaok 已提交
326 327
```

Z
zengyawen 已提交
328
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
329

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

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

X
xu-rui-w 已提交
334
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
335 336 337

**参数:**

Z
zengyawen 已提交
338 339 340 341
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| src      | ArrayBuffer          | 是   | 图像像素数据。                 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
342 343 344 345

**示例:**

```js
X
xu-rui-w 已提交
346
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
347
const pixelMap = new ArrayBuffer(400);
X
xu-rui-w 已提交
348
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
349
pixelMap.writeBufferToPixels(color, function(err) {
X
xiaok 已提交
350 351 352
    if (err) {
        console.error("Failed to write data from a buffer to a PixelMap.");
        return;
X
xu-rui-w 已提交
353 354 355
    } else {
		console.log("Succeeded in writing data from a buffer to a PixelMap.");
	}
X
xiaok 已提交
356 357 358
});
```

Z
zengyawen 已提交
359
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
360

Z
zengyawen 已提交
361
getImageInfo(): Promise\<ImageInfo>
X
xiaok 已提交
362 363 364

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

X
xu-rui-w 已提交
365
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
366 367 368

**返回值:**

Z
zengyawen 已提交
369 370 371
| 类型                              | 说明                                                        |
| --------------------------------- | ----------------------------------------------------------- |
| Promise\<[ImageInfo](#imageinfo)> | Promise实例,用于异步获取图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
372 373 374 375

**示例:**

```js
X
xu-rui-w 已提交
376 377
const pixelMap = new ArrayBuffer(400);
pixelMap.getImageInfo().then(function(info) {
X
xiaok 已提交
378 379 380 381 382 383
    console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => {
    console.error("Failed to obtain the image pixel map information.");
});
```

Z
zengyawen 已提交
384
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
385

Z
zengyawen 已提交
386
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
387 388 389

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

X
xu-rui-w 已提交
390
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
391 392 393

**参数:**

Z
zengyawen 已提交
394 395 396
| 参数名   | 类型                                    | 必填 | 说明                                                         |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 获取图像像素信息回调,异步返回图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
397 398 399 400

**示例:**

```js
X
xu-rui-w 已提交
401
pixelmap.getImageInfo((imageInfo) => { 
X
xu-rui-w 已提交
402
    console.log("Succeeded in obtaining the image pixel map information.");
X
xu-rui-w 已提交
403
})
X
xiaok 已提交
404 405
```

Z
zengyawen 已提交
406
### getBytesNumberPerRow<sup>7+</sup>
X
xiaok 已提交
407

Z
zengyawen 已提交
408
getBytesNumberPerRow(): number
X
xiaok 已提交
409 410 411

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

X
xu-rui-w 已提交
412
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
413 414 415

**返回值:**

Z
zengyawen 已提交
416 417 418
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的行字节数。 |
X
xiaok 已提交
419 420 421 422

**示例:**

```js
X
xu-rui-w 已提交
423
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
424
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
425
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
426
image.createPixelMap(color, opts, (err,pixelmap) => {
X
xu-rui-w 已提交
427 428
    let rowCount = pixelmap.getBytesNumberPerRow();
})
X
xiaok 已提交
429 430
```

X
xu-rui-w 已提交
431
### getPixelBytesNumber<sup>7+</sup>
X
xiaok 已提交
432

Z
zengyawen 已提交
433
getPixelBytesNumber(): number
X
xiaok 已提交
434 435 436

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

X
xu-rui-w 已提交
437
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
438 439 440

**返回值:**

Z
zengyawen 已提交
441 442 443
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的总字节数。 |
X
xiaok 已提交
444 445 446 447

**示例:**

```js
X
xu-rui-w 已提交
448
let pixelBytesNumber = pixelmap.getPixelBytesNumber();
X
xiaok 已提交
449 450
```

X
xu-rui-w 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
### getDensity<sup>9+</sup>

getDensity():number

获取当前的Density值。

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

**返回值:**

| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的Density值。|

**示例:**

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

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

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

通过设置透明比率来让PixelMap达到对应的透明效果,使用callback形式返回释放结果。

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
489
await pixelMap.opacity(0.5);
X
xu-rui-w 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
```

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

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

通过设置透明比率来让PixelMap达到对应的透明效果,使用Promise形式返回释放结果。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                        |
| ------ | ------ | ---- | --------------------------- |
| rate   | number | 是   | 透明比率的值,取值范围:0-1。|

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
515
await pixelMap.opacity(0.5);
X
xu-rui-w 已提交
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
```

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

createAlphaPixelmap(): Promise\<PixelMap>

根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用Promise形式返回释放结果。

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

**返回值:**

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

**示例:**

```js
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {
    if (alphaPixelMap == undefined) {
        console.info('Failed to obtain new pixel map.');
    } else {
        console.info('Succeed in obtaining new pixel map.');
    }
})
```

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

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

根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用callback形式返回释放结果。

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

**参数:**

| 参数名   | 类型                     | 必填 | 说明                         |
| -------- | ------------------------ | ---- | ---------------------------- |
| callback | AsyncCallback\<PixelMap> | 是   | 获取回调,异步返回释放结果。 |

**示例:**

```js
let pixelMap = await imageSource.createPixelMap();
if (pixelMap != undefined) {
    pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {
        console.info('Failed to obtain new pixel map.');    
    })
} else {
    console.info('Succeed in obtaining new pixel map.');
}
```

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

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

根据输入的宽高对图片进行缩放,使用callback形式返回释放结果。

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| x        | number               | 是   | 宽度的缩放值。                |
| y        | number               | 是   | 高度的缩放值。                |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
X
xu-rui-w 已提交
590 591 592
async function () {
	await pixelMap.scale(2.0, 1.0);
}
X
xu-rui-w 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
```

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

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

根据输入的宽高对图片进行缩放,使用Promise形式返回释放结果。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明          |
| ------ | ------ | ---- | ------------- |
| x      | number | 是   | 宽度的缩放值。|
| y      | number | 是   | 高度的缩放值。|

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
619 620 621
async function () {
	await pixelMap.scale(2.0, 1.0);
}
X
xu-rui-w 已提交
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
```

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

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

根据输入的坐标对图片进行位置变换,使用callback形式返回释放结果。

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
643 644 645
async function () {
	await pixelMap.translate(3.0, 1.0);
}
X
xu-rui-w 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
```

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

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

根据输入的坐标对图片进行位置变换,使用Promise形式返回释放结果。

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
672 673 674
async function () {
	await pixelMap.translate(3.0, 1.0);
}
X
xu-rui-w 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
```

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

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

根据输入的角度对图片进行旋转,使用callback形式返回释放结果。

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
695 696 697
async function () {
	await pixelMap.rotate(90.0);
}
X
xu-rui-w 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
```

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

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

根据输入的角度对图片进行旋转,使用Promise形式返回释放结果。

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
723 724 725
async function () {
	await pixelMap.rotate(90.0);
}
X
xu-rui-w 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
```

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

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

根据输入的条件对图片进行翻转,使用callback形式返回释放结果。

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
747 748 749
async function () {
	await pixelMap.flip(false, true);
}
X
xu-rui-w 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
```

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

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

根据输入的条件对图片进行翻转,使用Promise形式返回释放结果。

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
776 777 778
async function () {
	await pixelMap.flip(false, true);
}
X
xu-rui-w 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
```

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

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

根据输入的尺寸对图片进行裁剪,使用callback形式返回释放结果。

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明                          |
| -------- | -------------------- | ---- | ----------------------------- |
| region   | Region               | 是   | 裁剪的尺寸。                  |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。|

**示例:**

```js
X
xu-rui-w 已提交
799 800 801
async function () {
	await pixelMap.crop(3x3);
}
X
xu-rui-w 已提交
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
```

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

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

根据输入的尺寸对图片进行裁剪,使用Promise形式返回释放结果。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明        |
| ------ | ------ | ---- | ----------- |
| region | Region | 是   | 裁剪的尺寸。|

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
827 828 829
async function () {
	await pixelMap.crop(3x3);
}
X
xu-rui-w 已提交
830 831
```

Z
zengyawen 已提交
832
### release<sup>7+</sup>
X
xiaok 已提交
833

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

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

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

Z
zengyawen 已提交
840
**返回值:**
X
xiaok 已提交
841

X
xu-rui-w 已提交
842 843 844
| 类型           | 说明                            |
| -------------- | ------------------------------- |
| Promise\<void> | Promise实例,异步返回释放结果。 |
X
xiaok 已提交
845 846 847 848

**示例:**

```js
X
xu-rui-w 已提交
849
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
850
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
851
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
852 853
image.createPixelMap(color, opts, (pixelmap) => {
    pixelmap.release().then(() => {
X
xu-rui-w 已提交
854
	    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
855
    }).catch(error => {
X
xu-rui-w 已提交
856
	    console.log('Failed to release pixelmap object.');
X
xu-rui-w 已提交
857 858
    })
})
X
xiaok 已提交
859 860
```

Z
zengyawen 已提交
861
### release<sup>7+</sup>
X
xiaok 已提交
862

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

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

X
xu-rui-w 已提交
867
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
868 869 870

**参数:**

Z
zengyawen 已提交
871 872 873
| 名称     | 类型                 | 必填 | 说明               |
| -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | 是   | 异步返回释放结果。 |
X
xiaok 已提交
874 875 876 877

**示例:**

```js
X
xu-rui-w 已提交
878
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
879
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
880
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
881 882
image.createPixelMap(color, opts, (pixelmap) => {
    pixelmap.release().then(() => {
X
xu-rui-w 已提交
883
	    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
884
    }).catch(error => {
X
xu-rui-w 已提交
885
	    console.log('Failed to release pixelmap object.');
X
xu-rui-w 已提交
886 887
    })
})
X
xiaok 已提交
888 889
```

X
xu-rui-w 已提交
890
## image.createImageSource
X
xiaok 已提交
891

Z
zengyawen 已提交
892
createImageSource(uri: string): ImageSource
X
xiaok 已提交
893

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

X
xu-rui-w 已提交
896
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
897 898 899

**参数:**

Z
zengyawen 已提交
900 901
| 参数名 | 类型   | 必填 | 说明                               |
| ------ | ------ | ---- | ---------------------------------- |
Z
zhang-xiaobo1997 已提交
902
| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。 |
X
xiaok 已提交
903 904 905

**返回值:**

906 907 908
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
909 910 911 912

**示例:**

```js
Z
zhang-xiaobo1997 已提交
913 914
let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
X
xiaok 已提交
915 916
```

X
xu-rui-w 已提交
917
## image.createImageSource<sup>7+</sup>
X
xu-rui-w 已提交
918 919 920 921 922 923 924 925 926 927 928 929 930

createImageSource(fd: number): ImageSource

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

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

**参数:**

| 参数名 | 类型   | 必填 | 说明          |
| ------ | ------ | ---- | ------------- |
| fd     | number | 是   | 文件描述符fd。|

X
xu-rui-w 已提交
931 932 933 934 935 936
**返回值:**

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

X
xu-rui-w 已提交
937 938 939 940 941 942 943
**示例:**

```js
const imageSourceApi = image.createImageSource(0)
```

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

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

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

X
xu-rui-w 已提交
949
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
950 951 952

**参数:**

X
xu-rui-w 已提交
953 954 955
| 参数名 | 类型        | 必填 | 说明             |
| ------ | ----------- | ---- | ---------------- |
| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
X
xiaok 已提交
956 957 958 959

**示例:**

```js
X
xu-rui-w 已提交
960
const buf = new ArrayBuffer(96);
X
xu-rui-w 已提交
961
const imageSourceApi = image.createImageSource(buf);
X
xiaok 已提交
962 963
```

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

X
xu-rui-w 已提交
966
function CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
X
xu-rui-w 已提交
967

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

X
xu-rui-w 已提交
970
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
971 972 973 974 975

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                 |
| ------- | ------------------------------- | ---- | ------------------------------------ |
X
xu-rui-w 已提交
976 977
| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
| options | [SourceOptions](#SourceOptions) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
978 979 980 981 982 983 984 985 986 987 988

**返回值:**

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

**示例:**

```js
const buf = new ArrayBuffer(96);
X
xu-rui-w 已提交
989
const imageSourceApi = image.CreateIncrementalSource(buf);
X
xu-rui-w 已提交
990 991
```

Z
zengyawen 已提交
992
## ImageSource
X
xiaok 已提交
993

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

### 属性

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

Z
zengyawen 已提交
1000 1001
| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
Z
zhang-xiaobo1997 已提交
1002
| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。 |
Z
zengyawen 已提交
1003 1004 1005 1006

### getImageInfo

getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1007 1008 1009

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

X
xu-rui-w 已提交
1010
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1011 1012 1013

**参数:**

Z
zengyawen 已提交
1014 1015 1016 1017
| 参数名   | 类型                                   | 必填 | 说明                                     |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| index    | number                                 | 是   | 创建图片源时的序号。                     |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1018 1019 1020 1021

**示例:**

```js
X
xu-rui-w 已提交
1022 1023 1024 1025 1026 1027 1028
imageSourceApi.getImageInfo(0,(error, imageInfo) => { 
    if(error) {
        console.log('getImageInfo failed.');
    } else {
        console.log('getImageInfo succeeded.');
    }
})
X
xiaok 已提交
1029 1030
```

Z
zengyawen 已提交
1031
### getImageInfo
X
xiaok 已提交
1032

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

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

X
xu-rui-w 已提交
1037
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1038 1039 1040 1041 1042

**参数:**

| 名称     | 类型                                   | 必填 | 说明                                     |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
Z
zengyawen 已提交
1043
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1044 1045 1046 1047

**示例:**

```js
X
xu-rui-w 已提交
1048
imageSourceApi.getImageInfo(imageInfo => { 
X
xu-rui-w 已提交
1049
    console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1050
})
X
xiaok 已提交
1051 1052
```

Z
zengyawen 已提交
1053
### getImageInfo
X
xiaok 已提交
1054

Z
zengyawen 已提交
1055
getImageInfo(index?: number): Promise\<ImageInfo>
X
xiaok 已提交
1056 1057 1058

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

X
xu-rui-w 已提交
1059
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1060 1061 1062

**参数:**

Z
zengyawen 已提交
1063 1064 1065
| 名称  | 类型   | 必填 | 说明                                  |
| ----- | ------ | ---- | ------------------------------------- |
| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
X
xiaok 已提交
1066 1067 1068

**返回值:**

Z
zengyawen 已提交
1069 1070 1071
| 类型                             | 说明                   |
| -------------------------------- | ---------------------- |
| Promise<[ImageInfo](#imageinfo)> | 返回获取到的图片信息。 |
X
xiaok 已提交
1072 1073 1074 1075 1076

**示例:**

```js
imageSourceApi.getImageInfo(0)
X
xu-rui-w 已提交
1077
    .then(imageInfo => {
X
xu-rui-w 已提交
1078
		console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1079
	}).catch(error => {
X
xu-rui-w 已提交
1080
		console.log('Failed to obtain the image information.');
X
xu-rui-w 已提交
1081
	})
X
xiaok 已提交
1082 1083
```

Z
zengyawen 已提交
1084
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1085

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

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

X
xu-rui-w 已提交
1090
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1091 1092 1093

 **参数:**

Z
zengyawen 已提交
1094 1095 1096 1097
| 名称    | 类型                                                 | 必填 | 说明                                 |
| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
| key     | string                                               | 是   | 图片属性名。                         |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xiaok 已提交
1098 1099 1100

**返回值:**

Z
zengyawen 已提交
1101 1102 1103
| 类型             | 说明                                                         |
| ---------------- | ------------------------------------------------------------ |
| Promise\<string> | Promise实例,用于异步获取图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1104 1105 1106 1107

**示例:**

```js
1108
imageSourceApi.getImageProperty("BitsPerSample")
X
xu-rui-w 已提交
1109
    .then(data => {
X
xu-rui-w 已提交
1110
		console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1111
	})
X
xiaok 已提交
1112 1113
```

Z
zengyawen 已提交
1114
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1115

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

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

X
xu-rui-w 已提交
1120
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1121 1122 1123

 **参数:**

Z
zengyawen 已提交
1124 1125 1126 1127
| 参数名   | 类型                   | 必填 | 说明                                                         |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| key      | string                 | 是   | 图片属性名。                                                 |
| callback | AsyncCallback\<string> | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1128 1129 1130 1131

**示例:**

```js
X
xu-rui-w 已提交
1132 1133
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { 
    if(error) {
X
xu-rui-w 已提交
1134
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1135
    } else {
X
xu-rui-w 已提交
1136
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1137 1138
    }
})
X
xiaok 已提交
1139 1140
```

X
xu-rui-w 已提交
1141
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1142

Z
zengyawen 已提交
1143
getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1144 1145 1146

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

X
xu-rui-w 已提交
1147
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1148 1149 1150

**参数:**

Z
zengyawen 已提交
1151 1152 1153 1154 1155
| 参数名   | 类型                                                 | 必填 | 说明                                                         |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| key      | string                                               | 是   | 图片属性名。                                                 |
| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | 是   | 图片属性,包括图片序号与默认属性值。                         |
| callback | AsyncCallback\<string>                               | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1156 1157 1158 1159

**示例:**

```js
X
xu-rui-w 已提交
1160 1161
const property = new ArrayBuffer(400);
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { 
X
xu-rui-w 已提交
1162
    if(error) {
X
xu-rui-w 已提交
1163
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1164
    } else {
X
xu-rui-w 已提交
1165
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1166 1167
    }
})
X
xiaok 已提交
1168 1169
```

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

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

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

X
xu-rui-w 已提交
1176
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
1187 1188 1189
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200

**示例:**

```js
imageSourceApi.modifyImageProperty("ImageWidth", "abc")
            .then(() => {
                const w = imageSourceApi.getImageProperty("ImageWidth")
                console.info('w', w);
            })
```

X
xu-rui-w 已提交
1201
### modifyImageProperty<sup>9+</sup>
X
xu-rui-w 已提交
1202 1203 1204

modifyImageProperty(key: string, value: string, callback: AsyncCallback<void>): void

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

X
xu-rui-w 已提交
1207
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222

**参数:**

| 参数名   | 类型                | 必填 | 说明                           |
| -------- | ------------------- | ---- | ------------------------------ |
| key      | string              | 是   | 图片属性名。                   |
| value    | string              | 是   | 属性值。                       |
| callback | AsyncCallback<void> | 是   | 修改属性值,callback返回结果。 |

**示例:**

```js
imageSourceApi.modifyImageProperty("ImageWidth", "abc",() => {})
```

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

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

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

X
xu-rui-w 已提交
1229
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241

**参数:**

| 名称       | 类型        | 必填 | 说明         |
| ---------- | ----------- | ---- | ------------ |
| buf        | ArrayBuffer | 是   | 增量数据。   |
| isFinished | boolean     | 是   | 是否更新完。 |
| value      | number      | 否   | 偏移量。     |
| length     | number      | 否   | 数组长。     |

**返回值:**

X
xu-rui-w 已提交
1242 1243 1244
| 类型           | 说明                       |
| -------------- | -------------------------- |
| Promise\<void> | Promise实例,异步返回结果。|
X
xu-rui-w 已提交
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255

**示例:**

```js
const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10).then(data => {
            console.info('Succeeded in updating data.');
        })
```


X
xu-rui-w 已提交
1256
### updateData<sup>9+</sup>
X
xu-rui-w 已提交
1257 1258 1259

updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback<void>): void

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

X
xu-rui-w 已提交
1262
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279

**参数:**

| 名称       | 类型                | 必填 | 说明                 |
| ---------- | ------------------- | ---- | -------------------- |
| buf        | ArrayBuffer         | 是   | 增量数据。           |
| isFinished | boolean             | 是   | 是否更新完。         |
| value      | number              | 否   | 偏移量。             |
| length     | number              | 否   | 数组长。             |
| callback   | AsyncCallback<void> | 是   | 回调表示成功或失败。 |

**示例:**

```js
const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {
            if(data !== undefined){
X
xu-rui-w 已提交
1280
                console.info('Succeeded in updating data.');     
X
xu-rui-w 已提交
1281
            }
X
xu-rui-w 已提交
1282
		})
X
xu-rui-w 已提交
1283 1284
```

Z
zengyawen 已提交
1285
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1286

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

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

X
xu-rui-w 已提交
1291
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1292 1293 1294

**参数:**

Z
zengyawen 已提交
1295 1296 1297 1298 1299 1300 1301 1302 1303
| 名称    | 类型                                 | 必填 | 说明       |
| ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 异步返回Promise对象。 |
X
xiaok 已提交
1304 1305 1306 1307

**示例:**

```js
X
xu-rui-w 已提交
1308
imageSourceApi.createPixelMap().then(pixelmap => {
X
xu-rui-w 已提交
1309
    console.log('Succeeded in creating pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1310
}).catch(error => {
X
xu-rui-w 已提交
1311
    console.log('Failed to create pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1312
})
X
xiaok 已提交
1313 1314
```

Z
zengyawen 已提交
1315
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1316

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

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

X
xu-rui-w 已提交
1321
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1322 1323 1324

**参数:**

Z
zengyawen 已提交
1325 1326 1327
| 名称     | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1328 1329 1330 1331

**示例:**

```js
X
xu-rui-w 已提交
1332
imageSourceApi.createPixelMap(pixelmap => { 
X
xu-rui-w 已提交
1333
    console.log('Succeeded in creating pixelmap object.');
X
xu-rui-w 已提交
1334
}).catch(error => {
X
xu-rui-w 已提交
1335
    console.log('Failed to create pixelmap object.');
X
xu-rui-w 已提交
1336
})
X
xiaok 已提交
1337 1338
```

Z
zengyawen 已提交
1339
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1340

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

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

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

**参数:**

Z
zengyawen 已提交
1349 1350
| 名称     | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
1351
| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
Z
zengyawen 已提交
1352
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1353 1354 1355 1356

**示例:**

```js
X
xu-rui-w 已提交
1357
const decodingOptions = new ArrayBuffer(400);
X
xu-rui-w 已提交
1358
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { 
X
xu-rui-w 已提交
1359 1360
    console.log('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1361 1362
```

Z
zengyawen 已提交
1363
### release
X
xiaok 已提交
1364

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

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

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

**参数:**

Z
zengyawen 已提交
1373 1374 1375
| 名称     | 类型                 | 必填 | 说明                               |
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<void> | 是   | 资源释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1376 1377 1378 1379

**示例:**

```js
X
xu-rui-w 已提交
1380 1381 1382
imageSourceApi.release(() => { 
    console.log('release succeeded.');
})
X
xiaok 已提交
1383 1384
```

Z
zengyawen 已提交
1385
### release
X
xiaok 已提交
1386

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

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

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

Z
zengyawen 已提交
1393 1394 1395 1396 1397 1398
**返回值:**

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

X
xiaok 已提交
1399 1400 1401
**示例:**

```js
X
xu-rui-w 已提交
1402
imageSourceApi.release().then(()=>{
X
xu-rui-w 已提交
1403
    console.log('Succeeded in releasing the image source instance.');
X
xu-rui-w 已提交
1404
}).catch(error => {
X
xu-rui-w 已提交
1405
    console.log('Failed to release the image source instance.');
X
xu-rui-w 已提交
1406
})
X
xiaok 已提交
1407 1408
```

Z
zengyawen 已提交
1409
## image.createImagePacker
X
xiaok 已提交
1410 1411 1412

createImagePacker(): ImagePacker

Z
zengyawen 已提交
1413
创建ImagePacker实例。
X
xiaok 已提交
1414

X
xu-rui-w 已提交
1415
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
X
xiaok 已提交
1416 1417 1418

**返回值:**

Z
zengyawen 已提交
1419 1420 1421
| 类型                        | 说明                  |
| --------------------------- | --------------------- |
| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
X
xiaok 已提交
1422 1423 1424 1425 1426 1427 1428

**示例:**

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

Z
zengyawen 已提交
1429 1430 1431
## ImagePacker

图片打包器类,用于图片压缩和打包。在调用ImagePacker的方法前,需要先通过createImagePacker构建一个ImagePacker实例。
X
xiaok 已提交
1432

Z
zengyawen 已提交
1433 1434
### 属性

X
xu-rui-w 已提交
1435
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zhang-xiaobo1997 已提交
1436 1437 1438 1439

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

### packing

1443
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
X
xiaok 已提交
1444 1445 1446

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

X
xu-rui-w 已提交
1447
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1448 1449 1450

**参数:**

Z
zengyawen 已提交
1451 1452 1453 1454
| 参数名   | 类型                               | 必填 | 说明                               |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                     |
1455
| callback | AsyncCallback\<ArrayBuffer>        | 是   | 获取图片打包回调,返回打包后数据。 |
X
xiaok 已提交
1456 1457 1458 1459

**示例:**

```js
X
xu-rui-w 已提交
1460
let packOpts = { format:"image/jpeg", quality:98 };
X
xu-rui-w 已提交
1461 1462
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
X
xiaok 已提交
1463 1464
```

Z
zengyawen 已提交
1465
### packing
X
xiaok 已提交
1466

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

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

X
xu-rui-w 已提交
1471
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1472 1473 1474 1475 1476

**参数:**

| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
Z
zengyawen 已提交
1477 1478
| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
X
xiaok 已提交
1479 1480 1481

**返回值:**

Z
zengyawen 已提交
1482 1483
| 类型                         | 说明                                          |
| :--------------------------- | :-------------------------------------------- |
1484
| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。 |
X
xiaok 已提交
1485 1486 1487 1488

**示例:**

```js
X
xu-rui-w 已提交
1489
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1490 1491
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts)
X
xu-rui-w 已提交
1492 1493 1494 1495 1496
    .then( data => {
        console.log('packing succeeded.');
	}).catch(error => {
	    console.log('packing failed.');
	})
1497 1498
```

1499
### packing<sup>8+</sup>
1500

Z
zengyawen 已提交
1501
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
1502 1503 1504

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

X
xu-rui-w 已提交
1505
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1506 1507 1508 1509 1510 1511 1512

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
1518
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1519 1520 1521
const pixelMapApi = new ArrayBuffer(400);
imagePackerApi.packing(pixelMapApi, packOpts, data => { 
    console.log('Succeeded in packing the image.');
X
xu-rui-w 已提交
1522
}).catch(error => {
X
xu-rui-w 已提交
1523
	console.log('Failed to pack the image.');
X
xu-rui-w 已提交
1524
})
1525 1526
```

1527
### packing<sup>8+</sup>
1528

1529
packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
1530 1531 1532

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

X
xu-rui-w 已提交
1533
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1534 1535 1536

**参数:**

Z
zhang-xiaobo1997 已提交
1537 1538
| 参数名 | 类型                            | 必填 | 说明               |
| ------ | ------------------------------- | ---- | ------------------ |
1539
| source | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap源。 |
Z
zhang-xiaobo1997 已提交
1540
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
1541 1542 1543

**返回值:**

Z
zengyawen 已提交
1544 1545
| 类型                         | 说明                                          |
| :--------------------------- | :-------------------------------------------- |
1546
| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。 |
1547 1548 1549 1550

**示例:**

```js
X
xu-rui-w 已提交
1551
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1552 1553
const pixelMapApi = new ArrayBuffer(400);
imagePackerApi.packing(pixelMapApi, packOpts)
X
xu-rui-w 已提交
1554
    .then( data => {
X
xu-rui-w 已提交
1555
	    console.log('Succeeded in packing the image.');
X
xu-rui-w 已提交
1556
	}).catch(error => {
X
xu-rui-w 已提交
1557
	    console.log('Failed to pack the image..');
X
xu-rui-w 已提交
1558
	})
X
xiaok 已提交
1559 1560
```

Z
zengyawen 已提交
1561
### release
X
xiaok 已提交
1562

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

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

X
xu-rui-w 已提交
1567
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1568 1569 1570

**参数:**

Z
zengyawen 已提交
1571 1572 1573
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<void> | 是   | 释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1574 1575 1576 1577

**示例:**

```js
X
xu-rui-w 已提交
1578
imagePackerApi.release(()=>{ 
X
xu-rui-w 已提交
1579
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1580
})
X
xiaok 已提交
1581 1582
```

Z
zengyawen 已提交
1583
### release
X
xiaok 已提交
1584

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

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

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

Z
zengyawen 已提交
1591 1592
**返回值:**

Z
zengyawen 已提交
1593 1594 1595
| 类型           | 说明                                                    |
| :------------- | :------------------------------------------------------ |
| Promise\<void> | Promise实例,用于异步获取释放结果,失败时返回错误信息。 |
Z
zengyawen 已提交
1596

X
xiaok 已提交
1597 1598 1599
**示例:**

```js
X
xu-rui-w 已提交
1600
imagePackerApi.release().then(()=>{
X
xu-rui-w 已提交
1601
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1602
}).catch((error)=>{ 
X
xu-rui-w 已提交
1603
    console.log('Failed to release image packaging.'); 
X
xu-rui-w 已提交
1604
}) 
X
xiaok 已提交
1605 1606
```

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

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

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

Z
zengyawen 已提交
1613
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1614 1615 1616

**参数:**

Z
zengyawen 已提交
1617 1618 1619 1620 1621 1622
| 名称     | 类型   | 必填 | 说明                   |
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
| format   | number | 是   | 图像格式。             |
| capacity | number | 是   | 同时访问的最大图像数。 |
Z
zhang-xiaobo1997 已提交
1623 1624 1625

**返回值:**

Z
zengyawen 已提交
1626 1627 1628
| 类型                             | 说明                                    |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
Z
zhang-xiaobo1997 已提交
1629 1630 1631 1632

**示例:**

```js
X
xu-rui-w 已提交
1633
var receiver = image.createImageReceiver(8192, 8, 4, 8);
Z
zhang-xiaobo1997 已提交
1634
```
Z
zhang-xiaobo1997 已提交
1635

Z
zhang-xiaobo1997 已提交
1636 1637
## ImageReceiver<sup>9+</sup>

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

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

### 属性

1644
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1645

Z
zengyawen 已提交
1646 1647 1648 1649 1650
| 名称                  | 类型                         | 可读 | 可写 | 说明               |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup>     | [Size](#size)                | 是   | 否   | 图片大小。         |
| capacity<sup>9+</sup> | number                       | 是   | 否   | 同时访问的图像数。 |
| format<sup>9+</sup>   | [ImageFormat](#imageformat9) | 是   | 否   | 图像格式。         |
Z
zhang-xiaobo1997 已提交
1651

Z
zhang-xiaobo1997 已提交
1652
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1653

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

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

Z
zengyawen 已提交
1658
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1659 1660 1661

**参数:**

Z
zengyawen 已提交
1662 1663 1664
| 名称     | 类型                   | 必填 | 说明                       |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是   | 回调函数,返回surface id。 |
Z
zhang-xiaobo1997 已提交
1665 1666 1667 1668

**示例:**

```js
X
xu-rui-w 已提交
1669
receiver.getReceivingSurfaceId((err, id) => { 
X
xu-rui-w 已提交
1670 1671 1672 1673 1674 1675
    if(err) {
        console.log('getReceivingSurfaceId failed.');
    } else {
        console.log('getReceivingSurfaceId succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1676 1677
```

Z
zhang-xiaobo1997 已提交
1678
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1679

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

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

Z
zengyawen 已提交
1684
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1685 1686 1687

**返回值:**

Z
zhang-xiaobo1997 已提交
1688 1689 1690
| 类型             | 说明                 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
Z
zhang-xiaobo1997 已提交
1691 1692 1693 1694 1695

**示例:**

```js
receiver.getReceivingSurfaceId().then( id => { 
X
xu-rui-w 已提交
1696 1697 1698 1699
    console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
    console.log('getReceivingSurfaceId failed.');
})
Z
zhang-xiaobo1997 已提交
1700 1701
```

Z
zhang-xiaobo1997 已提交
1702
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1703

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

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

Z
zengyawen 已提交
1708
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1709 1710 1711

**参数:**

Z
zengyawen 已提交
1712 1713 1714
| 名称     | 类型                            | 必填 | 说明                     |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回最新图像。 |
Z
zhang-xiaobo1997 已提交
1715 1716 1717 1718

**示例:**

```js
X
xu-rui-w 已提交
1719 1720 1721 1722 1723 1724 1725
receiver.readLatestImage((err, img) => { 
    if(err) {
        console.log('readLatestImage failed.');
    } else {
        console.log('readLatestImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1726 1727
```

Z
zhang-xiaobo1997 已提交
1728
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1729

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

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

Z
zengyawen 已提交
1734
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1735 1736 1737 1738 1739

**返回值:**

| 类型                      | 说明               |
| ------------------------- | ------------------ |
Z
zhang-xiaobo1997 已提交
1740
| Promise<[Image](#image8)> | 异步返回最新图片。 |
Z
zhang-xiaobo1997 已提交
1741 1742 1743 1744

**示例:**

```js
X
xu-rui-w 已提交
1745 1746 1747 1748 1749
receiver.readLatestImage().then(img => {
    console.log('readLatestImage succeeded.');
}).catch(error => {
    console.log('readLatestImage failed.');
})
Z
zhang-xiaobo1997 已提交
1750 1751
```

Z
zhang-xiaobo1997 已提交
1752
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1753

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

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

Z
zengyawen 已提交
1758
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1759 1760 1761

**参数:**

Z
zengyawen 已提交
1762 1763 1764
| 名称     | 类型                            | 必填 | 说明                       |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1765 1766 1767 1768

**示例:**

```js
X
xu-rui-w 已提交
1769 1770 1771 1772 1773 1774 1775
receiver.readNextImage((err, img) => { 
    if(err) {
        console.log('readNextImage failed.');
    } else {
        console.log('readNextImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1776 1777
```

Z
zhang-xiaobo1997 已提交
1778
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1779

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

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

Z
zengyawen 已提交
1784
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1785 1786 1787 1788 1789

**返回值:**

| 类型                      | 说明                 |
| ------------------------- | -------------------- |
Z
zengyawen 已提交
1790
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1791 1792 1793 1794

**示例:**

```js
X
xu-rui-w 已提交
1795 1796 1797 1798 1799
receiver.readNextImage().then(img => {
    console.log('readNextImage succeeded.');
}).catch(error => {
    console.log('readNextImage failed.');
})
Z
zhang-xiaobo1997 已提交
1800 1801
```

Z
zengyawen 已提交
1802
### on('imageArrival')<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1803

Z
zhang-xiaobo1997 已提交
1804
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1805 1806 1807

接收图片时注册回调。

Z
zengyawen 已提交
1808
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1809 1810 1811

**参数:**

Z
zhang-xiaobo1997 已提交
1812 1813
| 名称     | 类型                 | 必填 | 说明                                                   |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
Z
zengyawen 已提交
1814
| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
Z
zhang-xiaobo1997 已提交
1815
| callback | AsyncCallback\<void> | 是   | 注册的事件回调。                                       |
Z
zhang-xiaobo1997 已提交
1816 1817 1818 1819

**示例:**

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

Z
zhang-xiaobo1997 已提交
1823
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1824

Z
zengyawen 已提交
1825
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1826 1827 1828

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

Z
zengyawen 已提交
1829
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1830 1831 1832

**参数:**

Z
zengyawen 已提交
1833 1834 1835
| 名称     | 类型                 | 必填 | 说明                     |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是   | 回调函数,返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1836 1837 1838 1839

**示例:**

```js
X
xu-rui-w 已提交
1840
receiver.release(() => {})
Z
zhang-xiaobo1997 已提交
1841 1842
```

Z
zhang-xiaobo1997 已提交
1843
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1844

Z
zhang-xiaobo1997 已提交
1845
release(): Promise\<void>
Z
zhang-xiaobo1997 已提交
1846 1847 1848

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

Z
zengyawen 已提交
1849
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1850 1851 1852

**返回值:**

Z
zengyawen 已提交
1853 1854 1855
| 类型           | 说明               |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1856 1857 1858 1859

**示例:**

```js
X
xu-rui-w 已提交
1860 1861 1862 1863 1864
receiver.release().then(() => {
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
1865 1866
```

Z
zhang-xiaobo1997 已提交
1867
## Image<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1868

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

### 属性

Z
zengyawen 已提交
1873
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
1874

Z
zengyawen 已提交
1875 1876
| 名称                  | 类型               | 可读 | 可写 | 说明                                               |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- |
1877
| clipRect<sup>9+</sup> | [Region](#region7) | 是   | 是   | 要裁剪的图像区域。                                 |
Z
zengyawen 已提交
1878 1879
| size<sup>9+</sup>     | [Size](#size)      | 是   | 否   | 图像大小。                                         |
| format<sup>9+</sup>   | number             | 是   | 否   | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 |
Z
zhang-xiaobo1997 已提交
1880

Z
zhang-xiaobo1997 已提交
1881
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1882

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

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

Z
zengyawen 已提交
1887
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
1888 1889 1890 1891 1892

**参数:**

| 名称          | 类型                                    | 必填 | 说明                 |
| ------------- | --------------------------------------- | ---- | -------------------- |
Z
zengyawen 已提交
1893 1894
| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。     |
| callback      | AsyncCallback<[Component](#component9)> | 是   | 用于返回组件缓冲区。 |
Z
zhang-xiaobo1997 已提交
1895 1896 1897 1898

**示例:**

```js
X
xu-rui-w 已提交
1899 1900 1901 1902 1903 1904 1905
img.getComponent(4, (err, component) => {
    if(err) {
        console.log('getComponent failed.');
    } else {
        console.log('getComponent succeeded.');
    }
})
Z
zhang-xiaobo1997 已提交
1906 1907
```

Z
zhang-xiaobo1997 已提交
1908
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1909

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

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

Z
zengyawen 已提交
1914
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
1915 1916 1917 1918 1919

**参数:**

| 名称          | 类型                             | 必填 | 说明             |
| ------------- | -------------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
1920
| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。 |
Z
zhang-xiaobo1997 已提交
1921 1922 1923 1924 1925

**返回值:**

| 类型                              | 说明                              |
| --------------------------------- | --------------------------------- |
Z
zengyawen 已提交
1926
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
Z
zhang-xiaobo1997 已提交
1927 1928 1929 1930 1931 1932 1933

**示例:**

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

Z
zhang-xiaobo1997 已提交
1934
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1935

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

Z
zengyawen 已提交
1938 1939 1940
释放当前图像并使用callback返回结果。

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

Z
zengyawen 已提交
1942
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
1943 1944 1945

**参数:**

Z
zhang-xiaobo1997 已提交
1946 1947 1948
| 名称     | 类型                 | 必填 | 说明           |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是   | 返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1949 1950 1951 1952

**示例:**

```js
X
xu-rui-w 已提交
1953 1954 1955 1956 1957
img.release(() =>{ 
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
}) 
Z
zhang-xiaobo1997 已提交
1958 1959
```

Z
zhang-xiaobo1997 已提交
1960
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1961

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

Z
zengyawen 已提交
1964 1965 1966
释放当前图像并使用Promise方式返回结果。

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

Z
zengyawen 已提交
1968
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
1969 1970 1971

**返回值:**

Z
zhang-xiaobo1997 已提交
1972 1973 1974
| 类型           | 说明                  |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1975 1976 1977 1978 1979

**示例:**

```js
img.release().then(() =>{
X
xu-rui-w 已提交
1980 1981 1982 1983
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
1984 1985
```

Z
zengyawen 已提交
1986 1987 1988 1989
## PositionArea<sup>7+</sup>

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

X
xu-rui-w 已提交
1990
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
1991

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

Z
zengyawen 已提交
1999
## ImageInfo
X
xiaok 已提交
2000

Z
zengyawen 已提交
2001
表示图片信息。
X
xiaok 已提交
2002

X
xu-rui-w 已提交
2003
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2004

Z
zengyawen 已提交
2005 2006 2007
| 名称 | 类型          | 可读 | 可写 | 说明       |
| ---- | ------------- | ---- | ---- | ---------- |
| size | [Size](#size) | 是   | 是   | 图片大小。 |
X
xiaok 已提交
2008

Z
zengyawen 已提交
2009
## Size
X
xiaok 已提交
2010

Z
zengyawen 已提交
2011 2012
表示图片尺寸。

X
xu-rui-w 已提交
2013
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2014 2015 2016 2017 2018 2019 2020

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

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

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

X
xu-rui-w 已提交
2024
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2025 2026 2027 2028 2029 2030 2031

| 名称      | 默认值 | 描述              |
| --------- | ------ | ----------------- |
| UNKNOWN   | 0      | 未知格式。        |
| RGBA_8888 | 3      | 格式为RGBA_8888。 |
| RGB_565   | 2      | 格式为RGB_565。   |

2032
## AlphaType<sup>9+</sup>
X
xiaok 已提交
2033

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

X
xu-rui-w 已提交
2036
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2037 2038 2039 2040 2041 2042 2043

| 名称     | 默认值 | 描述                    |
| -------- | ------ | ----------------------- |
| UNKNOWN  | 0      | 未知透明度。            |
| OPAQUE   | 1      | 没有alpha或图片全透明。 |
| PREMUL   | 2      | RGB前乘alpha。          |
| UNPREMUL | 3      | RGB不前乘alpha。        |
X
xiaok 已提交
2044

2045
## ScaleMode<sup>9+</sup>
X
xiaok 已提交
2046

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

X
xu-rui-w 已提交
2049
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
2050

Z
zengyawen 已提交
2051 2052 2053 2054
| 名称            | 默认值 | 描述                                               |
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
| FIT_TARGET_SIZE | 2      | 图像适合目标尺寸的效果。                           |
X
xiaok 已提交
2055

Z
zengyawen 已提交
2056
## InitializationOptions<sup>8+</sup>
X
xiaok 已提交
2057

Z
zengyawen 已提交
2058 2059
PixelMap的初始化选项。

X
xu-rui-w 已提交
2060
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Code
Z
zengyawen 已提交
2061

Z
zhang-xiaobo1997 已提交
2062 2063 2064 2065 2066 2067 2068
| 名称                   | 类型                               | 可读 | 可写 | 说明           |
| ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9)           | 是   | 是   | 透明度。       |
| editable               | boolean                            | 是   | 是   | 是否可编辑。   |
| pixelFormat            | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 像素格式。     |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9)           | 是   | 是   | 缩略值。       |
| size                   | [Size](#size)                      | 是   | 是   | 创建图片大小。 |
Z
zengyawen 已提交
2069 2070

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

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

X
xu-rui-w 已提交
2074
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2075 2076 2077 2078

| 名称               | 类型                               | 可读 | 可写 | 说明             |
| ------------------ | ---------------------------------- | ---- | ---- | ---------------- |
| sampleSize         | number                             | 是   | 是   | 缩略图采样大小。 |
Z
zengyawen 已提交
2079
| rotate             | number                             | 是   | 是   | 旋转角度。       |
Z
zengyawen 已提交
2080 2081
| editable           | boolean                            | 是   | 是   | 是否可编辑。     |
| desiredSize        | [Size](#size)                      | 是   | 是   | 期望输出大小。   |
2082
| desiredRegion      | [Region](#region7)                 | 是   | 是   | 解码区域。       |
Z
zengyawen 已提交
2083
| desiredPixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 解码的像素格式。 |
X
xu-rui-w 已提交
2084
| index              | number                             | 是   | 是   | 解码图片序号。   |
Z
zengyawen 已提交
2085

2086
## Region<sup>7+</sup>
Z
zengyawen 已提交
2087 2088 2089

表示区域信息。

X
xu-rui-w 已提交
2090
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2091

2092 2093 2094 2095 2096
| 名称 | 类型          | 可读 | 可写 | 说明         |
| ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | 是   | 是   | 区域大小。   |
| x    | number        | 是   | 是   | 区域横坐标。 |
| y    | number        | 是   | 是   | 区域纵坐标。 |
Z
zengyawen 已提交
2097 2098 2099 2100 2101

## PackingOption

表示图片打包选项。

X
xu-rui-w 已提交
2102
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImagePacker
Z
zengyawen 已提交
2103 2104 2105 2106

| 名称    | 类型   | 可读 | 可写 | 说明           |
| ------- | ------ | ---- | ---- | -------------- |
| format  | string | 是   | 是   | 目标格式。     |
X
xu-rui-w 已提交
2107
| quality | number | 是   | 是   | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
Z
zengyawen 已提交
2108 2109 2110 2111 2112

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

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

X
xu-rui-w 已提交
2113
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123

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

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

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

X
xu-rui-w 已提交
2124
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
2125

X
xu-rui-w 已提交
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
| 名称              | 默认值            | 说明                |
| ----------------- | ----------------- | ------------------- |
| BITS_PER_SAMPLE   | "BitsPerSample"   | 每个像素比特数。    |
| ORIENTATION       | "Orientation"     | 图片方向。          |
| IMAGE_LENGTH      | "ImageLength"     | 图片长度。          |
| IMAGE_WIDTH       | "ImageWidth"      | 图片宽度。          |
| GPS_LATITUDE      | "GPSLatitude"     | 图片纬度。          |
| GPS_LONGITUDE     | "GPSLongitude"    | 图片经度。          |
| GPS_LATITUDE_REF  | "GPSLatitudeRef"  | 纬度引用,例如N或S。|
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。|
2136

Z
zhang-xiaobo1997 已提交
2137
## ImageFormat<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2138 2139 2140

枚举,图片格式。

Z
zengyawen 已提交
2141
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2142

Z
zengyawen 已提交
2143 2144 2145 2146
| 名称         | 默认值 | 描述                 |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
| JPEG         | 2000   | JPEG编码格式。       |
Z
zhang-xiaobo1997 已提交
2147

Z
zengyawen 已提交
2148
## ComponentType<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2149 2150 2151

枚举,图像的组件类型。

Z
zengyawen 已提交
2152
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2153 2154 2155 2156 2157 2158 2159 2160

| 名称  | 默认值 | 描述        |
| ----- | ------ | ----------- |
| YUV_Y | 1      | 亮度信息。  |
| YUV_U | 2      | 色度信息。  |
| YUV_V | 3      | 色度信息。  |
| JPEG  | 4      | Jpeg 类型。 |

Z
zengyawen 已提交
2161
## Component<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2162 2163 2164

描述图像颜色分量。

Z
zengyawen 已提交
2165
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2166 2167 2168

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

X
xu-rui-w 已提交
2174
## ResponseCode
X
xu-rui-w 已提交
2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214

编译错误返回的响应码。

| 名称                                | 值       | 说明                                                |
| ----------------------------------- | -------- | --------------------------------------------------- |
| ERR_MEDIA_INVALID_VALUE             | -1       | 无效大小。                                          |
| SUCCESS                             | 0        | 操作成功。                                          |
| ERROR                               | 62980096 | 操作失败。                                          |
| ERR_IPC                             | 62980097 | ipc错误。                                           |
| ERR_SHAMEM_NOT_EXIST                | 62980098 | 共享内存错误。                                      |
| ERR_SHAMEM_DATA_ABNORMAL            | 62980099 | 共享内存错误。                                      |
| ERR_IMAGE_DECODE_ABNORMAL           | 62980100 | 图像解码错误。                                      |
| ERR_IMAGE_DATA_ABNORMAL             | 62980101 | 图像输入数据错误。                                  |
| ERR_IMAGE_MALLOC_ABNORMAL           | 62980102 | 图像malloc错误。                                    |
| ERR_IMAGE_DATA_UNSUPPORT            | 62980103 | 不支持图像类型。                                    |
| ERR_IMAGE_INIT_ABNORMAL             | 62980104 | 图像初始化错误。                                    |
| ERR_IMAGE_GET_DATA_ABNORMAL         | 62980105 | 图像获取数据错误。                                  |
| ERR_IMAGE_TOO_LARGE                 | 62980106 | 图像数据太大。                                      |
| ERR_IMAGE_TRANSFORM                 | 62980107 | 图像转换错误。                                      |
| ERR_IMAGE_COLOR_CONVERT             | 62980108 | 图像颜色转换错误。                                  |
| ERR_IMAGE_CROP                      | 62980109 | 裁剪错误。                                          |
| ERR_IMAGE_SOURCE_DATA               | 62980110 | 图像源数据错误。                                    |
| ERR_IMAGE_SOURCE_DATA_INCOMPLETE    | 62980111 | 图像源数据不完整。                                  |
| ERR_IMAGE_MISMATCHED_FORMAT         | 62980112 | 图像格式不匹配。                                    |
| ERR_IMAGE_UNKNOWN_FORMAT            | 62980113 | 图像未知格式。                                      |
| ERR_IMAGE_SOURCE_UNRESOLVED         | 62980114 | 图像源未解析。                                      |
| ERR_IMAGE_INVALID_PARAMETER         | 62980115 | 图像无效参数。                                      |
| ERR_IMAGE_DECODE_FAILED             | 62980116 | 解码失败。                                          |
| ERR_IMAGE_PLUGIN_REGISTER_FAILED    | 62980117 | 注册插件失败。                                      |
| ERR_IMAGE_PLUGIN_CREATE_FAILED      | 62980118 | 创建插件失败。                                      |
| ERR_IMAGE_ENCODE_FAILED             | 62980119 | 图像编码失败。                                      |
| ERR_IMAGE_ADD_PIXEL_MAP_FAILED      | 62980120 | 图像添加像素映射失败。                              |
| ERR_IMAGE_HW_DECODE_UNSUPPORT       | 62980121 | 不支持图像硬件解码。                                |
| ERR_IMAGE_DECODE_HEAD_ABNORMAL      | 62980122 | 图像解码头错误。                                    |
| ERR_IMAGE_DECODE_EXIF_UNSUPPORT     | 62980123 | 图像解码exif取消支持。                              |
| ERR_IMAGE_PROPERTY_NOT_EXIST        | 62980124 | 图像属性不存在;错误代码被媒体占用,图像从150开始。 |
| ERR_IMAGE_READ_PIXELMAP_FAILED      | 62980246 | 读取像素地图失败。                                  |
| ERR_IMAGE_WRITE_PIXELMAP_FAILED     | 62980247 | 写入像素映射失败。                                  |
| ERR_IMAGE_PIXELMAP_NOT_ALLOW_MODIFY | 62980248 | pixelmap不允许修改。                                |
| ERR_IMAGE_CONFIG_FAILED             | 62980259 | 配置错误。                                          |