js-apis-image.md 81.3 KB
Newer Older
Z
zengyawen 已提交
1
# 图片处理
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

**参数:**

X
xu-rui-w 已提交
24 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);
X
xu-rui-w 已提交
40
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
41 42 43 44
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then((pixelmap) => {
        })
X
xiaok 已提交
45 46
```

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

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

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

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
66
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
67
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
68
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
69 70 71 72 73 74 75
image.createPixelMap(color, opts, (error, pixelmap) => {
    if(error) {
        console.log('Failed to create pixelmap.');
    } else {
        console.log('Succeeded in creating pixelmap.');
    }
})
X
xiaok 已提交
76 77
```

Z
zengyawen 已提交
78
## PixelMap<sup>7+</sup>
Z
zengyawen 已提交
79 80 81 82 83

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

 ### 属性

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

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

Z
zengyawen 已提交
90
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
91

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
113
const readBuffer = new ArrayBuffer(96);
X
xu-rui-w 已提交
114 115
pixelmap.readPixelsToBuffer(readBuffer).then(() => {
    console.log('Succeeded in reading image pixel data.');  //符合条件则进入 
X
xu-rui-w 已提交
116
}).catch(error => {
X
xu-rui-w 已提交
117
    console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
118
})
X
xiaok 已提交
119 120
```

Z
zengyawen 已提交
121
### readPixelsToBuffer<sup>7+</sup>
X
xiaok 已提交
122

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

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

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
139
const readBuffer = new ArrayBuffer(96);
X
xu-rui-w 已提交
140
pixelmap.readPixelsToBuffer(readBuffer, (err, res) => {
X
xu-rui-w 已提交
141
    if(err) {
X
xu-rui-w 已提交
142
        console.log('Failed to read image pixel data.');  //不符合条件则进入
X
xu-rui-w 已提交
143
    } else {
X
xu-rui-w 已提交
144
        console.log('Succeeded in reading image pixel data.');  //符合条件则进入
X
xu-rui-w 已提交
145 146
    }
})
X
xiaok 已提交
147 148
```

Z
zengyawen 已提交
149
### readPixels<sup>7+</sup>
X
xiaok 已提交
150

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

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

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
172 173 174
const area = new ArrayBuffer(400);
pixelmap.readPixels(area).then(() => {
    console.log('Succeeded in reading the image data in the area.'); //符合条件则进入
X
xu-rui-w 已提交
175
}).catch(error => {
X
xu-rui-w 已提交
176
    console.log('Failed to read the image data in the area.'); //不符合条件则进入
X
xu-rui-w 已提交
177
})
X
xiaok 已提交
178 179
```

Z
zengyawen 已提交
180
### readPixels<sup>7+</sup>
X
xiaok 已提交
181

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

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

X
xu-rui-w 已提交
186
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
187 188 189

**参数:**

Z
zengyawen 已提交
190 191 192 193
| 参数名   | 类型                           | 必填 | 说明                           |
| -------- | ------------------------------ | ---- | ------------------------------ |
| area     | [PositionArea](#positionarea7) | 是   | 区域大小,根据区域读取。       |
| callback | AsyncCallback\<void>           | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
194 195 196 197

**示例:**

```js
X
xu-rui-w 已提交
198
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
199
let bufferArr = new Uint8Array(color);
200 201
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
X
xu-rui-w 已提交
202 203 204 205 206 207 208 209 210 211 212
    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');
        })
    }
213
})
X
xiaok 已提交
214 215
```

Z
zengyawen 已提交
216
### writePixels<sup>7+</sup>
X
xiaok 已提交
217

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

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

X
xu-rui-w 已提交
222
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
223 224 225

**参数:** 

Z
zengyawen 已提交
226 227
| 参数名 | 类型                           | 必填 | 说明                 |
| ------ | ------------------------------ | ---- | -------------------- |
Z
zengyawen 已提交
228
| area   | [PositionArea](#positionarea7) | 是   | 区域,根据区域写入。 |
X
xiaok 已提交
229 230 231

**返回值:**

Z
zengyawen 已提交
232 233 234
| 类型           | 说明                                                |
| :------------- | :-------------------------------------------------- |
| Promise\<void> | Promise实例,用于获取写入结果,失败时返回错误信息。 |
X
xiaok 已提交
235 236 237 238

**示例:**

```js
239
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
240
let bufferArr = new Uint8Array(color);
241 242 243 244
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
    .then( pixelmap => {
        if (pixelmap == undefined) {
X
xu-rui-w 已提交
245
            console.info('createPixelMap failed.');
246 247 248 249 250 251
        }
        const area = { pixels: new ArrayBuffer(8),
            offset: 0,
            stride: 8,
            region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
        }
X
xu-rui-w 已提交
252
        let bufferArr = new Uint8Array(area.pixels);
253 254 255 256 257 258 259 260 261 262 263 264
        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 已提交
265
    }).catch(error => {
266 267
        console.log('error: ' + error);
    })
X
xiaok 已提交
268 269
```

Z
zengyawen 已提交
270
### writePixels<sup>7+</sup>
X
xiaok 已提交
271

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

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

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

**参数:** 

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

**示例:**

```js
X
xu-rui-w 已提交
288 289
const area = new ArrayBuffer(400);
pixelmap.writePixels(area, (error) => {
X
xu-rui-w 已提交
290
    if (error != undefined) {
X
xu-rui-w 已提交
291
		console.info('Failed to write pixelmap into the specified area.');
X
xu-rui-w 已提交
292 293 294 295 296 297 298 299
	} 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 已提交
300
})
X
xiaok 已提交
301 302
```

Z
zengyawen 已提交
303
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
304

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

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

X
xu-rui-w 已提交
309
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
310 311 312

**参数:**

Z
zengyawen 已提交
313 314 315
| 参数名 | 类型        | 必填 | 说明           |
| ------ | ----------- | ---- | -------------- |
| src    | ArrayBuffer | 是   | 图像像素数据。 |
X
xiaok 已提交
316 317 318

**返回值:**

Z
zengyawen 已提交
319 320 321
| 类型           | 说明                                            |
| -------------- | ----------------------------------------------- |
| Promise\<void> | Promise实例,用于获取结果,失败时返回错误信息。 |
X
xiaok 已提交
322 323 324 325

**示例:**

```js
X
xu-rui-w 已提交
326
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
327
const pixelMap = new ArrayBuffer(400);
X
xu-rui-w 已提交
328
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
329
pixelMap.writeBufferToPixels(color).then(() => {
X
xiaok 已提交
330 331 332
    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 已提交
333
})
X
xiaok 已提交
334 335
```

Z
zengyawen 已提交
336
### writeBufferToPixels<sup>7+</sup>
X
xiaok 已提交
337

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

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

X
xu-rui-w 已提交
342
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
343 344 345

**参数:**

Z
zengyawen 已提交
346 347 348 349
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| src      | ArrayBuffer          | 是   | 图像像素数据。                 |
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。 |
X
xiaok 已提交
350 351 352 353

**示例:**

```js
X
xu-rui-w 已提交
354
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
355
const pixelMap = new ArrayBuffer(400);
X
xu-rui-w 已提交
356
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
357
pixelMap.writeBufferToPixels(color, function(err) {
X
xiaok 已提交
358 359 360
    if (err) {
        console.error("Failed to write data from a buffer to a PixelMap.");
        return;
X
xu-rui-w 已提交
361 362 363
    } else {
		console.log("Succeeded in writing data from a buffer to a PixelMap.");
	}
X
xiaok 已提交
364 365 366
});
```

Z
zengyawen 已提交
367
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
368

Z
zengyawen 已提交
369
getImageInfo(): Promise\<ImageInfo>
X
xiaok 已提交
370 371 372

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

X
xu-rui-w 已提交
373
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
374 375 376

**返回值:**

Z
zengyawen 已提交
377 378 379
| 类型                              | 说明                                                        |
| --------------------------------- | ----------------------------------------------------------- |
| Promise\<[ImageInfo](#imageinfo)> | Promise实例,用于异步获取图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
380 381 382 383

**示例:**

```js
X
xu-rui-w 已提交
384 385
const pixelMap = new ArrayBuffer(400);
pixelMap.getImageInfo().then(function(info) {
X
xiaok 已提交
386 387 388 389 390 391
    console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => {
    console.error("Failed to obtain the image pixel map information.");
});
```

Z
zengyawen 已提交
392
### getImageInfo<sup>7+</sup>
X
xiaok 已提交
393

Z
zengyawen 已提交
394
getImageInfo(callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
395 396 397

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

X
xu-rui-w 已提交
398
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
399 400 401

**参数:**

Z
zengyawen 已提交
402 403 404
| 参数名   | 类型                                    | 必填 | 说明                                                         |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[ImageInfo](#imageinfo)> | 是   | 获取图像像素信息回调,异步返回图像像素信息,失败时返回错误信息。 |
X
xiaok 已提交
405 406 407 408

**示例:**

```js
X
xu-rui-w 已提交
409
pixelmap.getImageInfo((imageInfo) => { 
X
xu-rui-w 已提交
410
    console.log("Succeeded in obtaining the image pixel map information.");
X
xu-rui-w 已提交
411
})
X
xiaok 已提交
412 413
```

Z
zengyawen 已提交
414
### getBytesNumberPerRow<sup>7+</sup>
X
xiaok 已提交
415

Z
zengyawen 已提交
416
getBytesNumberPerRow(): number
X
xiaok 已提交
417 418 419

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

X
xu-rui-w 已提交
420
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
421 422 423

**返回值:**

Z
zengyawen 已提交
424 425 426
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的行字节数。 |
X
xiaok 已提交
427 428 429 430

**示例:**

```js
X
xu-rui-w 已提交
431
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
432
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
433
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
434
image.createPixelMap(color, opts, (err,pixelmap) => {
X
xu-rui-w 已提交
435 436
    let rowCount = pixelmap.getBytesNumberPerRow();
})
X
xiaok 已提交
437 438
```

Z
zengyawen 已提交
439
### getPixelBytesNumber<sup>7+</sup>
X
xiaok 已提交
440

Z
zengyawen 已提交
441
getPixelBytesNumber(): number
X
xiaok 已提交
442 443 444

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

X
xu-rui-w 已提交
445
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
446 447 448

**返回值:**

Z
zengyawen 已提交
449 450 451
| 类型   | 说明                 |
| ------ | -------------------- |
| number | 图像像素的总字节数。 |
X
xiaok 已提交
452 453 454 455

**示例:**

```js
X
xu-rui-w 已提交
456
let pixelBytesNumber = pixelmap.getPixelBytesNumber();
X
xiaok 已提交
457 458
```

X
xu-rui-w 已提交
459 460 461 462
### getDensity<sup>9+</sup>

getDensity():number

X
xu-rui-w 已提交
463
获取当前图像像素的密度。
X
xu-rui-w 已提交
464 465 466 467 468

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

**返回值:**

X
xu-rui-w 已提交
469 470 471
| 类型   | 说明            |
| ------ | --------------- |
| number | 图像像素的密度。|
X
xu-rui-w 已提交
472 473 474 475 476 477 478 479 480 481 482

**示例:**

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

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

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

X
xu-rui-w 已提交
483
通过设置透明比率来让PixelMap达到对应的透明效果,使用callback形式返回。
X
xu-rui-w 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
497 498 499
async function () {
	await pixelMap.opacity(0.5);
}
X
xu-rui-w 已提交
500 501 502 503 504 505
```

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

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

X
xu-rui-w 已提交
506
通过设置透明比率来让PixelMap达到对应的透明效果,使用Promise形式返回。
X
xu-rui-w 已提交
507 508 509 510 511 512 513

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                        |
| ------ | ------ | ---- | --------------------------- |
X
xu-rui-w 已提交
514
| rate   | number | 是   | 透明比率的值,取值范围:0-1。|
X
xu-rui-w 已提交
515 516 517 518 519 520 521 522 523 524

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
525 526 527
async function () {
	await pixelMap.opacity(0.5);
}
X
xu-rui-w 已提交
528 529 530 531 532 533
```

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

createAlphaPixelmap(): Promise\<PixelMap>

X
xu-rui-w 已提交
534
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用Promise形式返回。
X
xu-rui-w 已提交
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

**系统能力:** 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

X
xu-rui-w 已提交
560
根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果,使用callback形式返回。
X
xu-rui-w 已提交
561 562 563 564 565

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

**参数:**

X
xu-rui-w 已提交
566 567 568
| 参数名   | 类型                     | 必填 | 说明                     |
| -------- | ------------------------ | ---- | ------------------------ |
| callback | AsyncCallback\<PixelMap> | 是   | 获取回调,异步返回结果。 |
X
xu-rui-w 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

**示例:**

```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

X
xu-rui-w 已提交
587
根据输入的宽高对图片进行缩放,使用callback形式返回。
X
xu-rui-w 已提交
588 589 590 591 592

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

**参数:**

X
xu-rui-w 已提交
593 594 595 596 597
| 参数名   | 类型                 | 必填 | 说明                            |
| -------- | -------------------- | ---- | ------------------------------- |
| x        | number               | 是   | 宽度的缩放值,其值为输入的倍数。|
| y        | number               | 是   | 高度的缩放值,其值为输入的倍数。|
| callback | AsyncCallback\<void> | 是   | 获取回调,失败时返回错误信息。  |
X
xu-rui-w 已提交
598 599 600 601

**示例:**

```js
X
xu-rui-w 已提交
602 603 604
async function () {
	await pixelMap.scale(2.0, 1.0);
}
X
xu-rui-w 已提交
605 606 607 608 609 610
```

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

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

X
xu-rui-w 已提交
611
根据输入的宽高对图片进行缩放,使用Promise形式返回。
X
xu-rui-w 已提交
612 613 614 615 616

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

**参数:**

X
xu-rui-w 已提交
617 618 619 620
| 参数名 | 类型   | 必填 | 说明                            |
| ------ | ------ | ---- | ------------------------------- |
| x      | number | 是   | 宽度的缩放值,其值为输入的倍数。|
| y      | number | 是   | 高度的缩放值,其值为输入的倍数。|
X
xu-rui-w 已提交
621 622 623

**返回值:**

X
xu-rui-w 已提交
624 625 626
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
627 628 629 630

**示例:**

```js
X
xu-rui-w 已提交
631 632 633
async function () {
	await pixelMap.scale(2.0, 1.0);
}
X
xu-rui-w 已提交
634 635 636 637 638 639
```

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

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

X
xu-rui-w 已提交
640
根据输入的坐标对图片进行位置变换,使用callback形式返回。
X
xu-rui-w 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
655 656 657
async function () {
	await pixelMap.translate(3.0, 1.0);
}
X
xu-rui-w 已提交
658 659 660 661 662 663
```

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

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

X
xu-rui-w 已提交
664
根据输入的坐标对图片进行位置变换,使用Promise形式返回。
X
xu-rui-w 已提交
665 666 667 668 669 670 671 672 673 674 675 676

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

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
677 678 679
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
680 681 682 683

**示例:**

```js
X
xu-rui-w 已提交
684 685 686
async function () {
	await pixelMap.translate(3.0, 1.0);
}
X
xu-rui-w 已提交
687 688 689 690 691 692
```

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

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

X
xu-rui-w 已提交
693
根据输入的角度对图片进行旋转,使用callback形式返回。
X
xu-rui-w 已提交
694 695 696 697 698 699 700 701 702 703 704 705 706

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
707 708 709
async function () {
	await pixelMap.rotate(90.0);
}
X
xu-rui-w 已提交
710 711 712 713 714 715
```

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

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

X
xu-rui-w 已提交
716
根据输入的角度对图片进行旋转,使用Promise形式返回。
X
xu-rui-w 已提交
717 718 719 720 721 722 723 724 725 726 727

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

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
728 729 730
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
731 732 733 734

**示例:**

```js
X
xu-rui-w 已提交
735 736 737
async function () {
	await pixelMap.rotate(90.0);
}
X
xu-rui-w 已提交
738 739 740 741 742 743
```

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

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

X
xu-rui-w 已提交
744
根据输入的条件对图片进行翻转,使用callback形式返回。
X
xu-rui-w 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757 758

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
759 760 761
async function () {
	await pixelMap.flip(false, true);
}
X
xu-rui-w 已提交
762 763 764 765 766 767
```

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

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

X
xu-rui-w 已提交
768
根据输入的条件对图片进行翻转,使用Promise形式返回。
X
xu-rui-w 已提交
769 770 771 772 773 774 775 776 777 778 779 780

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

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
781 782 783
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
784 785 786 787

**示例:**

```js
X
xu-rui-w 已提交
788 789 790
async function () {
	await pixelMap.flip(false, true);
}
X
xu-rui-w 已提交
791 792 793 794 795 796
```

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

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

X
xu-rui-w 已提交
797
根据输入的尺寸对图片进行裁剪,使用callback形式返回。
X
xu-rui-w 已提交
798 799 800 801 802 803 804

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

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
811
async function () {
812
	await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
813
}
X
xu-rui-w 已提交
814 815 816 817 818 819
```

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

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

X
xu-rui-w 已提交
820
根据输入的尺寸对图片进行裁剪,使用Promise形式返回。
X
xu-rui-w 已提交
821 822 823 824 825

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

**参数:**

X
xu-rui-w 已提交
826 827 828
| 参数名 | 类型               | 必填 | 说明        |
| ------ | ------------------ | ---- | ----------- |
| region | [Region](#region7) | 是   | 裁剪的尺寸。|
X
xu-rui-w 已提交
829 830 831

**返回值:**

X
xu-rui-w 已提交
832 833 834
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
835 836 837 838

**示例:**

```js
X
xu-rui-w 已提交
839
async function () {
840
	await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
X
xu-rui-w 已提交
841
}
X
xu-rui-w 已提交
842 843
```

Z
zengyawen 已提交
844
### release<sup>7+</sup>
X
xiaok 已提交
845

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

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

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

Z
zengyawen 已提交
852
**返回值:**
X
xiaok 已提交
853

X
xu-rui-w 已提交
854 855 856
| 类型           | 说明                            |
| -------------- | ------------------------------- |
| Promise\<void> | Promise实例,异步返回释放结果。 |
X
xiaok 已提交
857 858 859 860

**示例:**

```js
X
xu-rui-w 已提交
861
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
862
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
863
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
864 865
image.createPixelMap(color, opts, (pixelmap) => {
    pixelmap.release().then(() => {
X
xu-rui-w 已提交
866
	    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
867
    }).catch(error => {
X
xu-rui-w 已提交
868
	    console.log('Failed to release pixelmap object.');
X
xu-rui-w 已提交
869 870
    })
})
X
xiaok 已提交
871 872
```

Z
zengyawen 已提交
873
### release<sup>7+</sup>
X
xiaok 已提交
874

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

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

X
xu-rui-w 已提交
879
**系统能力:** SystemCapability.Multimedia.Image.Core
X
xiaok 已提交
880 881 882

**参数:**

Z
zengyawen 已提交
883 884 885
| 名称     | 类型                 | 必填 | 说明               |
| -------- | -------------------- | ---- | ------------------ |
| callback | AsyncCallback\<void> | 是   | 异步返回释放结果。 |
X
xiaok 已提交
886 887 888 889

**示例:**

```js
X
xu-rui-w 已提交
890
const color = new ArrayBuffer(96);
X
xu-rui-w 已提交
891
let bufferArr = new Uint8Array(color);
X
xu-rui-w 已提交
892
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
X
xu-rui-w 已提交
893 894
image.createPixelMap(color, opts, (pixelmap) => {
    pixelmap.release().then(() => {
X
xu-rui-w 已提交
895
	    console.log('Succeeded in releasing pixelmap object.');
X
xu-rui-w 已提交
896 897
    })
})
X
xiaok 已提交
898 899
```

Z
zengyawen 已提交
900
## image.createImageSource
X
xiaok 已提交
901

Z
zengyawen 已提交
902
createImageSource(uri: string): ImageSource
X
xiaok 已提交
903

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

X
xu-rui-w 已提交
906
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
907 908 909

**参数:**

Z
zengyawen 已提交
910 911
| 参数名 | 类型   | 必填 | 说明                               |
| ------ | ------ | ---- | ---------------------------------- |
X
xu-rui-w 已提交
912
| uri    | string | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW。 |
X
xiaok 已提交
913 914 915

**返回值:**

916 917 918
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
919 920 921 922

**示例:**

```js
Z
zhang-xiaobo1997 已提交
923 924
let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
X
xiaok 已提交
925 926
```

X
xu-rui-w 已提交
927 928 929 930 931 932 933 934 935 936 937 938
## image.createImageSource<sup>9+</sup>

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

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

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

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
X
xu-rui-w 已提交
939
| uri     | string                          | 是   | 图片路径,当前仅支持应用沙箱路径。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW。 |
940
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
941 942 943 944 945 946 947 948 949 950

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
951
const imageSourceApi = image.createImageSource('/sdcard/test.jpg');
X
xu-rui-w 已提交
952 953
```

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

Z
zengyawen 已提交
956
createImageSource(fd: number): ImageSource
X
xiaok 已提交
957

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

X
xu-rui-w 已提交
960
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
961 962 963

**参数:**

X
xu-rui-w 已提交
964 965 966
| 参数名 | 类型   | 必填 | 说明          |
| ------ | ------ | ---- | ------------- |
| fd     | number | 是   | 文件描述符fd。|
X
xiaok 已提交
967 968 969

**返回值:**

970 971 972
| 类型                        | 说明                                         |
| --------------------------- | -------------------------------------------- |
| [ImageSource](#imagesource) | 返回ImageSource类实例,失败时返回undefined。 |
X
xiaok 已提交
973 974 975 976

**示例:**

```js
X
xu-rui-w 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
const imageSourceApi = image.createImageSource(0);
```

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

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

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

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

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                |
| ------- | ------------------------------- | ---- | ----------------------------------- |
| fd      | number                          | 是   | 文件描述符fd。                      |
993
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。|
X
xu-rui-w 已提交
994 995 996 997 998 999 1000 1001 1002 1003

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
1004
const imageSourceApi = image.createImageSource(fd);
X
xu-rui-w 已提交
1005 1006 1007
```

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

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

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

X
xu-rui-w 已提交
1013
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1014 1015 1016

**参数:**

X
xu-rui-w 已提交
1017 1018 1019
| 参数名 | 类型        | 必填 | 说明             |
| ------ | ----------- | ---- | ---------------- |
| buf    | ArrayBuffer | 是   | 图像缓冲区数组。 |
X
xiaok 已提交
1020 1021 1022 1023

**示例:**

```js
X
xu-rui-w 已提交
1024
const buf = new ArrayBuffer(96);
X
xu-rui-w 已提交
1025
const imageSourceApi = image.createImageSource(buf);
X
xiaok 已提交
1026 1027
```

X
xu-rui-w 已提交
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
## image.createImageSource<sup>9+</sup>

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

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

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

**参数:**

| 参数名 | 类型                             | 必填 | 说明                                 |
| ------ | -------------------------------- | ---- | ------------------------------------ |
| buf    | ArrayBuffer                      | 是   | 图像缓冲区数组。                     |
1041
| options | [SourceOptions](#sourceoptions9) | 是   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
1052 1053
const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);
X
xu-rui-w 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
```

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

CreateIncrementalSource(buf: ArrayBuffer): ImageSource

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

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

**参数:**

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

**返回值:**

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

**示例:**

```js
X
xu-rui-w 已提交
1079 1080
const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf);
X
xu-rui-w 已提交
1081 1082
```

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

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

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

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

**参数:**

| 参数名  | 类型                            | 必填 | 说明                                 |
| ------- | ------------------------------- | ---- | ------------------------------------ |
X
xu-rui-w 已提交
1095
| buf     | ArrayBuffer                     | 是   | 增量数据。                           |
1096
| options | [SourceOptions](#sourceoptions9) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xu-rui-w 已提交
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107

**返回值:**

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

**示例:**

```js
const buf = new ArrayBuffer(96);
X
xu-rui-w 已提交
1108
const imageSourceApi = image.CreateIncrementalSource(buf);
X
xiaok 已提交
1109 1110
```

Z
zengyawen 已提交
1111
## ImageSource
X
xiaok 已提交
1112

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

### 属性

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

Z
zengyawen 已提交
1119 1120
| 名称             | 类型           | 可读 | 可写 | 说明                                                         |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
Z
zhang-xiaobo1997 已提交
1121
| supportedFormats | Array\<string> | 是   | 否   | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。 |
Z
zengyawen 已提交
1122 1123 1124 1125

### getImageInfo

getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
X
xiaok 已提交
1126 1127 1128

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

X
xu-rui-w 已提交
1129
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1130 1131 1132

**参数:**

Z
zengyawen 已提交
1133 1134 1135 1136
| 参数名   | 类型                                   | 必填 | 说明                                     |
| -------- | -------------------------------------- | ---- | ---------------------------------------- |
| index    | number                                 | 是   | 创建图片源时的序号。                     |
| callback | AsyncCallback<[ImageInfo](#imageinfo)> | 是   | 获取图片信息回调,异步返回图片信息对象。 |
X
xiaok 已提交
1137 1138 1139 1140

**示例:**

```js
X
xu-rui-w 已提交
1141 1142 1143 1144 1145 1146 1147
imageSourceApi.getImageInfo(0,(error, imageInfo) => { 
    if(error) {
        console.log('getImageInfo failed.');
    } else {
        console.log('getImageInfo succeeded.');
    }
})
X
xiaok 已提交
1148 1149
```

Z
zengyawen 已提交
1150
### getImageInfo
X
xiaok 已提交
1151

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

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

X
xu-rui-w 已提交
1156
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1157 1158 1159 1160 1161

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
1167
imageSourceApi.getImageInfo(imageInfo => { 
X
xu-rui-w 已提交
1168
    console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1169
})
X
xiaok 已提交
1170 1171
```

Z
zengyawen 已提交
1172
### getImageInfo
X
xiaok 已提交
1173

Z
zengyawen 已提交
1174
getImageInfo(index?: number): Promise\<ImageInfo>
X
xiaok 已提交
1175 1176 1177

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

X
xu-rui-w 已提交
1178
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1179 1180 1181

**参数:**

Z
zengyawen 已提交
1182 1183 1184
| 名称  | 类型   | 必填 | 说明                                  |
| ----- | ------ | ---- | ------------------------------------- |
| index | number | 否   | 创建图片源时的序号,不选择时默认为0。 |
X
xiaok 已提交
1185 1186 1187

**返回值:**

Z
zengyawen 已提交
1188 1189 1190
| 类型                             | 说明                   |
| -------------------------------- | ---------------------- |
| Promise<[ImageInfo](#imageinfo)> | 返回获取到的图片信息。 |
X
xiaok 已提交
1191 1192 1193 1194 1195

**示例:**

```js
imageSourceApi.getImageInfo(0)
X
xu-rui-w 已提交
1196
    .then(imageInfo => {
X
xu-rui-w 已提交
1197
		console.log('Succeeded in obtaining the image information.');
X
xu-rui-w 已提交
1198
	}).catch(error => {
X
xu-rui-w 已提交
1199
		console.log('Failed to obtain the image information.');
X
xu-rui-w 已提交
1200
	})
X
xiaok 已提交
1201 1202
```

Z
zengyawen 已提交
1203
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1204

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

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

X
xu-rui-w 已提交
1209
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1210 1211 1212

 **参数:**

Z
zengyawen 已提交
1213 1214 1215 1216
| 名称    | 类型                                                 | 必填 | 说明                                 |
| ------- | ---------------------------------------------------- | ---- | ------------------------------------ |
| key     | string                                               | 是   | 图片属性名。                         |
| options | [GetImagePropertyOptions](#getimagepropertyoptions7) | 否   | 图片属性,包括图片序号与默认属性值。 |
X
xiaok 已提交
1217 1218 1219

**返回值:**

X
xu-rui-w 已提交
1220 1221
| 类型             | 说明                                                              |
| ---------------- | ----------------------------------------------------------------- |
Z
zengyawen 已提交
1222
| Promise\<string> | Promise实例,用于异步获取图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1223 1224 1225 1226

**示例:**

```js
1227
imageSourceApi.getImageProperty("BitsPerSample")
X
xu-rui-w 已提交
1228
    .then(data => {
X
xu-rui-w 已提交
1229
		console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1230
	})
X
xiaok 已提交
1231 1232
```

Z
zengyawen 已提交
1233
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1234

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

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

X
xu-rui-w 已提交
1239
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1240 1241 1242

 **参数:**

Z
zengyawen 已提交
1243 1244 1245 1246
| 参数名   | 类型                   | 必填 | 说明                                                         |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| key      | string                 | 是   | 图片属性名。                                                 |
| callback | AsyncCallback\<string> | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。 |
X
xiaok 已提交
1247 1248 1249 1250

**示例:**

```js
X
xu-rui-w 已提交
1251 1252
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => { 
    if(error) {
X
xu-rui-w 已提交
1253
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1254
    } else {
X
xu-rui-w 已提交
1255
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1256 1257
    }
})
X
xiaok 已提交
1258 1259
```

Z
zengyawen 已提交
1260
### getImageProperty<sup>7+</sup>
X
xiaok 已提交
1261

Z
zengyawen 已提交
1262
getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\<string>): void
X
xiaok 已提交
1263 1264 1265

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

X
xu-rui-w 已提交
1266
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1267 1268 1269

**参数:**

X
xu-rui-w 已提交
1270 1271 1272 1273 1274
| 参数名   | 类型                                                 | 必填 | 说明                                                          |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- |
| key      | string                                               | 是   | 图片属性名。                                                  |
| options  | [GetImagePropertyOptions](#getimagepropertyoptions7) | 是   | 图片属性,包括图片序号与默认属性值。                          |
| callback | AsyncCallback\<string>                               | 是   | 获取图片属性回调,返回图片属性值,如获取失败则返回属性默认值。|
X
xiaok 已提交
1275 1276 1277 1278

**示例:**

```js
X
xu-rui-w 已提交
1279 1280
const property = new ArrayBuffer(400);
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { 
X
xu-rui-w 已提交
1281
    if(error) {
X
xu-rui-w 已提交
1282
        console.log('Failed to get the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1283
    } else {
X
xu-rui-w 已提交
1284
        console.log('Succeeded in getting the value of the specified attribute key of the image.');
X
xu-rui-w 已提交
1285 1286
    }
})
X
xiaok 已提交
1287 1288
```

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

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

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

X
xu-rui-w 已提交
1295
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
1306 1307 1308
| 类型           | 说明                        |
| -------------- | --------------------------- |
| Promise\<void> | Promise实例,异步返回结果。 |
X
xu-rui-w 已提交
1309 1310 1311 1312

**示例:**

```js
X
xu-rui-w 已提交
1313
imageSourceApi.modifyImageProperty("ImageWidth", "120")
X
xu-rui-w 已提交
1314 1315 1316 1317 1318 1319
            .then(() => {
                const w = imageSourceApi.getImageProperty("ImageWidth")
                console.info('w', w);
            })
```

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

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

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

X
xu-rui-w 已提交
1326
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1327 1328 1329 1330 1331 1332 1333

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
1339
imageSourceApi.modifyImageProperty("ImageWidth", "120",() => {})
X
xu-rui-w 已提交
1340 1341
```

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

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

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

X
xu-rui-w 已提交
1348
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360

**参数:**

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

**返回值:**

X
xu-rui-w 已提交
1361 1362 1363
| 类型           | 说明                       |
| -------------- | -------------------------- |
| Promise\<void> | Promise实例,异步返回结果。|
X
xu-rui-w 已提交
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374

**示例:**

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


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

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

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

X
xu-rui-w 已提交
1381
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xu-rui-w 已提交
1382 1383 1384 1385 1386 1387 1388 1389 1390

**参数:**

| 名称       | 类型                | 必填 | 说明                 |
| ---------- | ------------------- | ---- | -------------------- |
| buf        | ArrayBuffer         | 是   | 增量数据。           |
| isFinished | boolean             | 是   | 是否更新完。         |
| value      | number              | 否   | 偏移量。             |
| length     | number              | 否   | 数组长。             |
1391
| callback   | AsyncCallback\<void> | 是   | 回调表示成功或失败。 |
X
xu-rui-w 已提交
1392 1393 1394 1395 1396 1397 1398

**示例:**

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

Z
zengyawen 已提交
1404
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1405

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

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

X
xu-rui-w 已提交
1410
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1411 1412 1413

**参数:**

Z
zengyawen 已提交
1414 1415 1416 1417 1418 1419 1420 1421 1422
| 名称    | 类型                                 | 必填 | 说明       |
| ------- | ------------------------------------ | ---- | ---------- |
| options | [DecodingOptions](#decodingoptions7) | 否   | 解码参数。 |

**返回值:**

| 类型                             | 说明                  |
| -------------------------------- | --------------------- |
| Promise\<[PixelMap](#pixelmap7)> | 异步返回Promise对象。 |
X
xiaok 已提交
1423 1424 1425 1426

**示例:**

```js
X
xu-rui-w 已提交
1427
imageSourceApi.createPixelMap().then(pixelmap => {
X
xu-rui-w 已提交
1428
    console.log('Succeeded in creating pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1429
}).catch(error => {
X
xu-rui-w 已提交
1430
    console.log('Failed to create pixelmap object through image decoding parameters.');
X
xu-rui-w 已提交
1431
})
X
xiaok 已提交
1432 1433
```

Z
zengyawen 已提交
1434
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1435

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

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

X
xu-rui-w 已提交
1440
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1441 1442 1443

**参数:**

Z
zengyawen 已提交
1444 1445 1446
| 名称     | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1447 1448 1449 1450

**示例:**

```js
X
xu-rui-w 已提交
1451
imageSourceApi.createPixelMap((err, pixelmap) => {
1452
                    console.info('Succeeded in creating pixelmap object.');
X
xu-rui-w 已提交
1453
                })
X
xiaok 已提交
1454 1455
```

Z
zengyawen 已提交
1456
### createPixelMap<sup>7+</sup>
X
xiaok 已提交
1457

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

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

X
xu-rui-w 已提交
1462
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1463 1464 1465

**参数:**

Z
zengyawen 已提交
1466 1467
| 名称     | 类型                                  | 必填 | 说明                       |
| -------- | ------------------------------------- | ---- | -------------------------- |
1468
| options  | [DecodingOptions](#decodingoptions7)  | 是   | 解码参数。                 |
Z
zengyawen 已提交
1469
| callback | AsyncCallback<[PixelMap](#pixelmap7)> | 是   | 通过回调返回PixelMap对象。 |
X
xiaok 已提交
1470 1471 1472 1473

**示例:**

```js
X
xu-rui-w 已提交
1474
const decodingOptions = new ArrayBuffer(400);
X
xu-rui-w 已提交
1475
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { 
X
xu-rui-w 已提交
1476 1477
    console.log('Succeeded in creating pixelmap object.');
})
X
xiaok 已提交
1478 1479
```

Z
zengyawen 已提交
1480
### release
X
xiaok 已提交
1481

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

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

X
xu-rui-w 已提交
1486
**系统能力:** SystemCapability.Multimedia.Image.ImageSource
X
xiaok 已提交
1487 1488 1489

**参数:**

Z
zengyawen 已提交
1490 1491 1492
| 名称     | 类型                 | 必填 | 说明                               |
| -------- | -------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<void> | 是   | 资源释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1493 1494 1495 1496

**示例:**

```js
X
xu-rui-w 已提交
1497 1498 1499
imageSourceApi.release(() => { 
    console.log('release succeeded.');
})
X
xiaok 已提交
1500 1501
```

Z
zengyawen 已提交
1502
### release
X
xiaok 已提交
1503

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

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

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

Z
zengyawen 已提交
1510 1511 1512 1513 1514 1515
**返回值:**

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

X
xiaok 已提交
1516 1517 1518
**示例:**

```js
X
xu-rui-w 已提交
1519
imageSourceApi.release().then(()=>{
X
xu-rui-w 已提交
1520
    console.log('Succeeded in releasing the image source instance.');
X
xu-rui-w 已提交
1521
}).catch(error => {
X
xu-rui-w 已提交
1522
    console.log('Failed to release the image source instance.');
X
xu-rui-w 已提交
1523
})
X
xiaok 已提交
1524 1525
```

Z
zengyawen 已提交
1526
## image.createImagePacker
X
xiaok 已提交
1527 1528 1529

createImagePacker(): ImagePacker

Z
zengyawen 已提交
1530
创建ImagePacker实例。
X
xiaok 已提交
1531

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

**返回值:**

Z
zengyawen 已提交
1536 1537 1538
| 类型                        | 说明                  |
| --------------------------- | --------------------- |
| [ImagePacker](#imagepacker) | 返回ImagePacker实例。 |
X
xiaok 已提交
1539 1540 1541 1542 1543 1544 1545

**示例:**

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

Z
zengyawen 已提交
1546 1547 1548
## ImagePacker

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

Z
zengyawen 已提交
1550 1551
### 属性

X
xu-rui-w 已提交
1552
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
Z
zhang-xiaobo1997 已提交
1553 1554 1555 1556

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

### packing

1560
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
X
xiaok 已提交
1561 1562 1563

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

X
xu-rui-w 已提交
1564
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1565 1566 1567

**参数:**

Z
zengyawen 已提交
1568 1569 1570
| 参数名   | 类型                               | 必填 | 说明                               |
| -------- | ---------------------------------- | ---- | ---------------------------------- |
| source   | [ImageSource](#imagesource)        | 是   | 打包的图片源。                     |
X
xu-rui-w 已提交
1571
| option   | [PackingOption](#packingoption)    | 是   | 设置打包参数。                      |
1572
| callback | AsyncCallback\<ArrayBuffer>        | 是   | 获取图片打包回调,返回打包后数据。 |
X
xiaok 已提交
1573 1574 1575 1576

**示例:**

```js
X
xu-rui-w 已提交
1577
let packOpts = { format:"image/jpeg", quality:98 };
X
xu-rui-w 已提交
1578 1579
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts, data => {})
X
xiaok 已提交
1580 1581
```

Z
zengyawen 已提交
1582
### packing
X
xiaok 已提交
1583

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

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

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

**参数:**

| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
Z
zengyawen 已提交
1594 1595
| source | [ImageSource](#imagesource)     | 是   | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。 |
X
xiaok 已提交
1596 1597 1598

**返回值:**

Z
zengyawen 已提交
1599
| 类型                         | 说明                                          |
X
xu-rui-w 已提交
1600 1601
| ---------------------------- | --------------------------------------------- |
| Promise\<ArrayBuffer>        | Promise实例,用于异步获取压缩或打包后的数据。 |
X
xiaok 已提交
1602 1603 1604 1605

**示例:**

```js
X
xu-rui-w 已提交
1606
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1607 1608
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts)
X
xu-rui-w 已提交
1609 1610 1611 1612 1613
    .then( data => {
        console.log('packing succeeded.');
	}).catch(error => {
	    console.log('packing failed.');
	})
1614 1615
```

1616
### packing<sup>8+</sup>
1617

Z
zengyawen 已提交
1618
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
1619 1620 1621

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

X
xu-rui-w 已提交
1622
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1623 1624 1625 1626 1627 1628 1629

**参数:**

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

**示例:**

```js
X
xu-rui-w 已提交
1635
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1636 1637 1638
const pixelMapApi = new ArrayBuffer(400);
imagePackerApi.packing(pixelMapApi, packOpts, data => { 
    console.log('Succeeded in packing the image.');
X
xu-rui-w 已提交
1639
})
1640 1641
```

1642
### packing<sup>8+</sup>
1643

1644
packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
1645 1646 1647

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

X
xu-rui-w 已提交
1648
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
1649 1650 1651

**参数:**

Z
zhang-xiaobo1997 已提交
1652 1653
| 参数名 | 类型                            | 必填 | 说明               |
| ------ | ------------------------------- | ---- | ------------------ |
1654
| source | [PixelMap](#pixelmap)           | 是   | 打包的PixelMap源。 |
Z
zhang-xiaobo1997 已提交
1655
| option | [PackingOption](#packingoption) | 是   | 设置打包参数。     |
1656 1657 1658

**返回值:**

X
xu-rui-w 已提交
1659 1660 1661
| 类型                  | 说明                                         |
| --------------------- | -------------------------------------------- |
| Promise\<ArrayBuffer> | Promise实例,用于异步获取压缩或打包后的数据。|
1662 1663 1664 1665

**示例:**

```js
X
xu-rui-w 已提交
1666
let packOpts = { format:"image/jpeg", quality:98 }
X
xu-rui-w 已提交
1667 1668
const pixelMapApi = new ArrayBuffer(400);
imagePackerApi.packing(pixelMapApi, packOpts)
X
xu-rui-w 已提交
1669
    .then( data => {
X
xu-rui-w 已提交
1670
	    console.log('Succeeded in packing the image.');
X
xu-rui-w 已提交
1671
	}).catch(error => {
X
xu-rui-w 已提交
1672
	    console.log('Failed to pack the image..');
X
xu-rui-w 已提交
1673
	})
X
xiaok 已提交
1674 1675
```

Z
zengyawen 已提交
1676
### release
X
xiaok 已提交
1677

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

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

X
xu-rui-w 已提交
1682
**系统能力:** SystemCapability.Multimedia.Image.ImagePacker
X
xiaok 已提交
1683 1684 1685

**参数:**

Z
zengyawen 已提交
1686 1687 1688
| 参数名   | 类型                 | 必填 | 说明                           |
| -------- | -------------------- | ---- | ------------------------------ |
| callback | AsyncCallback\<void> | 是   | 释放回调,失败时返回错误信息。 |
X
xiaok 已提交
1689 1690 1691 1692

**示例:**

```js
X
xu-rui-w 已提交
1693
imagePackerApi.release(()=>{ 
X
xu-rui-w 已提交
1694
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1695
})
X
xiaok 已提交
1696 1697
```

Z
zengyawen 已提交
1698
### release
X
xiaok 已提交
1699

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

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

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

Z
zengyawen 已提交
1706 1707
**返回值:**

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

X
xiaok 已提交
1712 1713 1714
**示例:**

```js
X
xu-rui-w 已提交
1715
imagePackerApi.release().then(()=>{
X
xu-rui-w 已提交
1716
    console.log('Succeeded in releasing image packaging.');
X
xu-rui-w 已提交
1717
}).catch((error)=>{ 
X
xu-rui-w 已提交
1718
    console.log('Failed to release image packaging.'); 
X
xu-rui-w 已提交
1719
}) 
X
xiaok 已提交
1720 1721
```

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

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

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

Z
zengyawen 已提交
1728
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1729 1730 1731

**参数:**

Z
zengyawen 已提交
1732 1733 1734 1735 1736 1737
| 名称     | 类型   | 必填 | 说明                   |
| -------- | ------ | ---- | ---------------------- |
| width    | number | 是   | 图像的默认宽度。       |
| height   | number | 是   | 图像的默认高度。       |
| format   | number | 是   | 图像格式。             |
| capacity | number | 是   | 同时访问的最大图像数。 |
Z
zhang-xiaobo1997 已提交
1738 1739 1740

**返回值:**

Z
zengyawen 已提交
1741 1742 1743
| 类型                             | 说明                                    |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
Z
zhang-xiaobo1997 已提交
1744 1745 1746 1747

**示例:**

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

Z
zhang-xiaobo1997 已提交
1751 1752
## ImageReceiver<sup>9+</sup>

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

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

### 属性

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

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

Z
zhang-xiaobo1997 已提交
1767
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1768

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

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

Z
zengyawen 已提交
1773
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1774 1775 1776

**参数:**

Z
zengyawen 已提交
1777 1778 1779
| 名称     | 类型                   | 必填 | 说明                       |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是   | 回调函数,返回surface id。 |
Z
zhang-xiaobo1997 已提交
1780 1781 1782 1783

**示例:**

```js
X
xu-rui-w 已提交
1784
receiver.getReceivingSurfaceId((err, id) => { 
X
xu-rui-w 已提交
1785 1786 1787 1788 1789 1790
    if(err) {
        console.log('getReceivingSurfaceId failed.');
    } else {
        console.log('getReceivingSurfaceId succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1791 1792
```

Z
zhang-xiaobo1997 已提交
1793
### getReceivingSurfaceId<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1794

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

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

Z
zengyawen 已提交
1799
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1800 1801 1802

**返回值:**

Z
zhang-xiaobo1997 已提交
1803 1804 1805
| 类型             | 说明                 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
Z
zhang-xiaobo1997 已提交
1806 1807 1808 1809 1810

**示例:**

```js
receiver.getReceivingSurfaceId().then( id => { 
X
xu-rui-w 已提交
1811 1812 1813 1814
    console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
    console.log('getReceivingSurfaceId failed.');
})
Z
zhang-xiaobo1997 已提交
1815 1816
```

Z
zhang-xiaobo1997 已提交
1817
### readLatestImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1818

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

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

Z
zengyawen 已提交
1823
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1824 1825 1826

**参数:**

Z
zengyawen 已提交
1827 1828 1829
| 名称     | 类型                            | 必填 | 说明                     |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回最新图像。 |
Z
zhang-xiaobo1997 已提交
1830 1831 1832 1833

**示例:**

```js
X
xu-rui-w 已提交
1834 1835 1836 1837 1838 1839 1840
receiver.readLatestImage((err, img) => { 
    if(err) {
        console.log('readLatestImage failed.');
    } else {
        console.log('readLatestImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1841 1842
```

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

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

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

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

**返回值:**

| 类型                      | 说明               |
| ------------------------- | ------------------ |
1855
| Promise<[Image](#image9)> | 异步返回最新图片。 |
Z
zhang-xiaobo1997 已提交
1856 1857 1858 1859

**示例:**

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

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

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

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

Z
zengyawen 已提交
1873
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1874 1875 1876

**参数:**

Z
zengyawen 已提交
1877 1878 1879
| 名称     | 类型                            | 必填 | 说明                       |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是   | 回调函数,返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1880 1881 1882 1883

**示例:**

```js
X
xu-rui-w 已提交
1884 1885 1886 1887 1888 1889 1890
receiver.readNextImage((err, img) => { 
    if(err) {
        console.log('readNextImage failed.');
    } else {
        console.log('readNextImage succeeded.');
    }
});
Z
zhang-xiaobo1997 已提交
1891 1892
```

Z
zhang-xiaobo1997 已提交
1893
### readNextImage<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1894

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

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

Z
zengyawen 已提交
1899
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1900 1901 1902 1903 1904

**返回值:**

| 类型                      | 说明                 |
| ------------------------- | -------------------- |
Z
zengyawen 已提交
1905
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
Z
zhang-xiaobo1997 已提交
1906 1907 1908 1909

**示例:**

```js
X
xu-rui-w 已提交
1910 1911 1912 1913 1914
receiver.readNextImage().then(img => {
    console.log('readNextImage succeeded.');
}).catch(error => {
    console.log('readNextImage failed.');
})
Z
zhang-xiaobo1997 已提交
1915 1916
```

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

Z
zhang-xiaobo1997 已提交
1919
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1920 1921 1922

接收图片时注册回调。

Z
zengyawen 已提交
1923
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1924 1925 1926

**参数:**

Z
zhang-xiaobo1997 已提交
1927 1928
| 名称     | 类型                 | 必填 | 说明                                                   |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
Z
zengyawen 已提交
1929
| type     | string               | 是   | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
Z
zhang-xiaobo1997 已提交
1930
| callback | AsyncCallback\<void> | 是   | 注册的事件回调。                                       |
Z
zhang-xiaobo1997 已提交
1931 1932 1933 1934

**示例:**

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

Z
zhang-xiaobo1997 已提交
1938
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1939

Z
zengyawen 已提交
1940
release(callback: AsyncCallback\<void>): void
Z
zhang-xiaobo1997 已提交
1941 1942 1943

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

Z
zengyawen 已提交
1944
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1945 1946 1947

**参数:**

Z
zengyawen 已提交
1948 1949 1950
| 名称     | 类型                 | 必填 | 说明                     |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是   | 回调函数,返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1951 1952 1953 1954

**示例:**

```js
X
xu-rui-w 已提交
1955
receiver.release(() => {})
Z
zhang-xiaobo1997 已提交
1956 1957
```

Z
zhang-xiaobo1997 已提交
1958
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1959

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

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

Z
zengyawen 已提交
1964
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
1965 1966 1967

**返回值:**

Z
zengyawen 已提交
1968 1969 1970
| 类型           | 说明               |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
Z
zhang-xiaobo1997 已提交
1971 1972 1973 1974

**示例:**

```js
X
xu-rui-w 已提交
1975 1976 1977 1978 1979
receiver.release().then(() => {
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
1980 1981
```

Z
zhang-xiaobo1997 已提交
1982
## Image<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1983

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

### 属性

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

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

Z
zhang-xiaobo1997 已提交
1996
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
1997

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

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

Z
zengyawen 已提交
2002
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2003 2004 2005 2006 2007

**参数:**

| 名称          | 类型                                    | 必填 | 说明                 |
| ------------- | --------------------------------------- | ---- | -------------------- |
Z
zengyawen 已提交
2008 2009
| componentType | [ComponentType](#componenttype9)        | 是   | 图像的组件类型。     |
| callback      | AsyncCallback<[Component](#component9)> | 是   | 用于返回组件缓冲区。 |
Z
zhang-xiaobo1997 已提交
2010 2011 2012 2013

**示例:**

```js
X
xu-rui-w 已提交
2014 2015 2016 2017 2018 2019 2020
img.getComponent(4, (err, component) => {
    if(err) {
        console.log('getComponent failed.');
    } else {
        console.log('getComponent succeeded.');
    }
})
Z
zhang-xiaobo1997 已提交
2021 2022
```

Z
zhang-xiaobo1997 已提交
2023
### getComponent<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2024

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

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

Z
zengyawen 已提交
2029
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2030 2031 2032 2033 2034

**参数:**

| 名称          | 类型                             | 必填 | 说明             |
| ------------- | -------------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
2035
| componentType | [ComponentType](#componenttype9) | 是   | 图像的组件类型。 |
Z
zhang-xiaobo1997 已提交
2036 2037 2038 2039 2040

**返回值:**

| 类型                              | 说明                              |
| --------------------------------- | --------------------------------- |
Z
zengyawen 已提交
2041
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
Z
zhang-xiaobo1997 已提交
2042 2043 2044 2045 2046 2047 2048

**示例:**

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

Z
zhang-xiaobo1997 已提交
2049
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2050

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

Z
zengyawen 已提交
2053 2054 2055
释放当前图像并使用callback返回结果。

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

Z
zengyawen 已提交
2057
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2058 2059 2060

**参数:**

Z
zhang-xiaobo1997 已提交
2061 2062 2063
| 名称     | 类型                 | 必填 | 说明           |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是   | 返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2064 2065 2066 2067

**示例:**

```js
X
xu-rui-w 已提交
2068 2069 2070
img.release(() =>{ 
    console.log('release succeeded.');
}) 
Z
zhang-xiaobo1997 已提交
2071 2072
```

Z
zhang-xiaobo1997 已提交
2073
### release<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2074

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

Z
zengyawen 已提交
2077 2078 2079
释放当前图像并使用Promise方式返回结果。

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

Z
zengyawen 已提交
2081
**系统能力:** SystemCapability.Multimedia.Image.Core
Z
zhang-xiaobo1997 已提交
2082 2083 2084

**返回值:**

Z
zhang-xiaobo1997 已提交
2085 2086 2087
| 类型           | 说明                  |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
Z
zhang-xiaobo1997 已提交
2088 2089 2090 2091 2092

**示例:**

```js
img.release().then(() =>{
X
xu-rui-w 已提交
2093 2094 2095 2096
    console.log('release succeeded.');
}).catch(error => {
    console.log('release failed.');
})
Z
zhang-xiaobo1997 已提交
2097 2098
```

Z
zengyawen 已提交
2099 2100 2101 2102
## PositionArea<sup>7+</sup>

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

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

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

Z
zengyawen 已提交
2112
## ImageInfo
X
xiaok 已提交
2113

Z
zengyawen 已提交
2114
表示图片信息。
X
xiaok 已提交
2115

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

Z
zengyawen 已提交
2118 2119 2120
| 名称 | 类型          | 可读 | 可写 | 说明       |
| ---- | ------------- | ---- | ---- | ---------- |
| size | [Size](#size) | 是   | 是   | 图片大小。 |
X
xiaok 已提交
2121

Z
zengyawen 已提交
2122
## Size
X
xiaok 已提交
2123

Z
zengyawen 已提交
2124 2125
表示图片尺寸。

X
xu-rui-w 已提交
2126
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2127 2128 2129 2130 2131 2132 2133

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

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

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

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

X
xu-rui-w 已提交
2139 2140 2141 2142 2143 2144
| 名称                   | 默认值 | 描述              |
| ---------------------- | ------ | ----------------- |
| UNKNOWN                | 0      | 未知格式。        |
| RGB_565                | 2      | 格式为RGB_565     |
| RGBA_8888              | 3      | 格式为RGBA_8888。 |
| BGRA_8888<sup>9+</sup> | 4      | 格式为BGRA_8888。 |
Z
zengyawen 已提交
2145

2146
## AlphaType<sup>9+</sup>
X
xiaok 已提交
2147

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

X
xu-rui-w 已提交
2150
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
Z
zengyawen 已提交
2151 2152 2153 2154 2155 2156 2157

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

2159
## ScaleMode<sup>9+</sup>
X
xiaok 已提交
2160

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

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

Z
zengyawen 已提交
2165 2166 2167
| 名称            | 默认值 | 描述                                               |
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP     | 1      | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
X
xu-rui-w 已提交
2168
| FIT_TARGET_SIZE | 0      | 图像适合目标尺寸的效果。                           |
X
xiaok 已提交
2169

X
xu-rui-w 已提交
2170 2171 2172 2173 2174 2175
## SourceOptions<sup>9+</sup>

ImageSource的初始化选项。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core

X
xu-rui-w 已提交
2176 2177 2178 2179 2180
| 名称              | 类型                               | 可读 | 可写 | 说明               |
| ----------------- | ---------------------------------- | ---- | ---- | ------------------ |
| sourceDensity     | number                             | 是   | 是   | ImageSource的密度。|
| sourcePixelFormat | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 图片像素格式。     |
| sourceSize        | [Size](#size)                      | 是   | 是   | 图像像素大小。     |
X
xu-rui-w 已提交
2181 2182


Z
zengyawen 已提交
2183
## InitializationOptions<sup>8+</sup>
X
xiaok 已提交
2184

Z
zengyawen 已提交
2185 2186
PixelMap的初始化选项。

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

X
xu-rui-w 已提交
2189 2190 2191
| 名称                     | 类型                               | 可读 | 可写 | 说明           |
| ------------------------ | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup>   | [AlphaType](#alphatype9)           | 是   | 是   | 透明度。       |
X
xu-rui-w 已提交
2192 2193
| editable                 | boolean                            | 是   | 是   | 是否可编辑。   |
| pixelFormat              | [PixelMapFormat](#pixelmapformat7) | 是   | 是   | 像素格式。     |
X
xu-rui-w 已提交
2194
| scaleMode<sup>9+</sup>   | [ScaleMode](#scalemode9)           | 是   | 是   | 缩略值。       |
X
xu-rui-w 已提交
2195
| size                     | [Size](#size)                      | 是   | 是   | 创建图片大小。 |
Z
zengyawen 已提交
2196 2197

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

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

X
xu-rui-w 已提交
2201
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2202 2203 2204 2205

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

2213
## Region<sup>7+</sup>
Z
zengyawen 已提交
2214 2215 2216

表示区域信息。

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

2219 2220 2221 2222 2223
| 名称 | 类型          | 可读 | 可写 | 说明         |
| ---- | ------------- | ---- | ---- | ------------ |
| size | [Size](#size) | 是   | 是   | 区域大小。   |
| x    | number        | 是   | 是   | 区域横坐标。 |
| y    | number        | 是   | 是   | 区域纵坐标。 |
Z
zengyawen 已提交
2224 2225 2226 2227 2228

## PackingOption

表示图片打包选项。

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

X
xu-rui-w 已提交
2231 2232
| 名称    | 类型   | 可读 | 可写 | 说明                                                |
| ------- | ------ | ---- | ---- | --------------------------------------------------- |
X
xu-rui-w 已提交
2233
| format  | string | 是   | 是   | 目标格式。</br>当前支持格式有:.jpg .png .gif .bmp .webp RAW。  |
X
xu-rui-w 已提交
2234
| quality | number | 是   | 是   | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
Z
zengyawen 已提交
2235 2236 2237 2238 2239

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

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

X
xu-rui-w 已提交
2240
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageSource
Z
zengyawen 已提交
2241 2242 2243 2244 2245 2246 2247 2248 2249 2250

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

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

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

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

X
xu-rui-w 已提交
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
| 名称              | 默认值                  | 说明                     |
| ----------------- | ----------------------- | ------------------------ |
| 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。     |
2263

Z
zhang-xiaobo1997 已提交
2264
## ImageFormat<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2265 2266 2267

枚举,图片格式。

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

Z
zengyawen 已提交
2270 2271 2272 2273
| 名称         | 默认值 | 描述                 |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000   | YCBCR422半平面格式。 |
| JPEG         | 2000   | JPEG编码格式。       |
Z
zhang-xiaobo1997 已提交
2274

Z
zengyawen 已提交
2275
## ComponentType<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2276 2277 2278

枚举,图像的组件类型。

Z
zengyawen 已提交
2279
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
Z
zhang-xiaobo1997 已提交
2280 2281 2282 2283 2284 2285 2286 2287

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

Z
zengyawen 已提交
2288
## Component<sup>9+</sup>
Z
zhang-xiaobo1997 已提交
2289 2290 2291

描述图像颜色分量。

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

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

X
xu-rui-w 已提交
2301
## ResponseCode
X
xu-rui-w 已提交
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341

编译错误返回的响应码。

| 名称                                | 值       | 说明                                                |
| ----------------------------------- | -------- | --------------------------------------------------- |
| 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 | 配置错误。                                          |